Barinex() and bar # under the crossbar

When I loop through bars (eg for (bar =1; bar < barCount ;bar++)

BarIndex[bar] does not match the bar displayed under the crossbar (it is always shifted by 1), so when the BarIndex[bar] = x, bar under the crossbar = x+1).
Any idea why ? and what to do in afl , so they much.
Thank you

Bar index is zero based whereas barcount is number of bars in the array
Just google amibroker barcount versus barindex gives this link
Read down—- Common Coding mistakes


Well, for programmers the only way to access bars is by using BarIndex() function which is zero based. Now imagine that you are not a programmer, but a software tester or a user who try to verify signals produced by a program . They go and view charts to verify signals. Obviously, under the cross bar, bar numbers, which are not zero based, do not much bar numbers generated by programs.
They have all the rights to claim that programs don't work !!

Index is not bar number. In C/C++ indexing starts at zero too.

Also see this thread for index vs. bar number.

Some other external information..

Zero-based numbering - Wikipedia.

Not correct.
E.g. printf( "%g", C[ i ] ); accesses and outputs an element of array (a value at some bar) and is not using BarIndex() function.

Another example:
bar_value = LookUp(C,_DT("2021-12-01")); does not use BarIndex() too to access a bar.


So as usual there are many ways to access a bar.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.