BarIndex
- get zero-based bar number

Date/Time
(AmiBroker 4.30)


SYNTAX BarIndex()
RETURNS ARRAY
FUNCTION returns zero-based bar number - the same as Cum(1)-1 but it is much faster than Cum(1) when used in Indicators New in 5.30: BarIndex() now returns values always starting from zero (even if QuickAFL is turned on). This change is required because Cum() now does not require all bars and formulas mixing Cum(1) and BarIndex would work improperly otherwise.
EXAMPLE ThisIsLastBar = BarIndex() == LastValue( BarIndex() );
SEE ALSO CUM() function

Comments:

Tomasz Janeczko
tj --at-- amibroker.com
2004-07-23 07:07:29
When QuickAFL is ON, the BarIndex() may not be equal with array item index.

Actual array item
corresponding to bar index can be found this way:

bi = BarIndex();
arrayitem = SelectedValue( bi ) - bi[ 0 ];
"Close at selected bar:" + Close[ arrayitem ];
Rolly
rollyzhang [at] hotmail.com
2007-11-03 14:12:22
BarIndex() returns an array and LastValue() returns a number. The API's example compares the two to give the boolean ThisIsLastBar. How could an array be compared with a number? How could it work? Please explain.
Tomasz Janeczko
tj at amibroker dot com
2007-11-04 09:14:21
That's simple - it compares each array element to a number and produces array as a result. Detailed explanation in User's Guide: Tutorial: Understanding AFL

References:

The BarIndex function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.