Hi, I’m new to AFL. I understand that most functions return arrays.
But how can I access the array element at the current bar?
BarIndex() itself returns an array. So mom[BarIndex()] won’t work (see attachment).
I know I could use cond = IIf(mom > minmom, True, False) instead.
But I would like to know anyway.
@Peter2047 I understand that.
But isn't AB iterating through the code and arrays bar by bar anyway when processing a script?
So how do I identify the current bar then, i.e. the correct [i] at this point of date?
I don't need the values before and after, just the one at the current bar.
I'm used to a TradeStation/EasyLanguage kind of logic and I haven't yet got AB/AFLs logic.
@GA2024 No, in fact AB is NOT running your AFL once for every bar in the array. For an analysis (scan, explore, backtest), AmiBroker will run your AFL once per symbol, with built-in variables like Open, High, Low, Close holding the entire price array for that symbol. Similarly to update a chart, AmiBroker will run the AFL one time, not once per bar.
Because of this, there is no concept of a "current" bar. You could consider the bar that's selected on the chart as the "current" bar, or you could consider the last bar of data available for the symbol in your database as the "current" (i.e. most recent) bar. It all depends on context.
For many operations, you will want to operate on the entire array at once. For example, if I want to calculate the range of all bars I might do something like this:
range = H - L;
The result of this statement is that the range variable contains an array, and each element of the array is the difference between the high and low from the corresponding elements in those arrays.