BarNumber

BarNumber ();

Description

Returns the current bar number.

Example 1

declare lower;
input length = 14;
plot RSquared = Sqr(Correlation(BarNumber(), close, length));

The output value of BarNumber increments by one on each new bar and represents a linear dependency. For this reason it can be used to calculate values for the RSquared plot that approximates the price with the linear regression trendline.

Example 2

declare lower;
plot Data = if BarNumber() <= 5 then 100 else if BarNumber() == 6 or BarNumber() == 7 then 150 else 200;

The examples draws the Data plot depending on the bar number. If the number is less or equal to 5 then its value is 100, if the number is 5 or 6 then 150, in the rest of the cases its value is 200.