It's always a challenge to work with AFL if one comes from a procedural programming (C, C++, Java etc.) background as AFL is a vector programming language (another e.g. being R). In AFL, data can be readily used as an array of OHLC, V and OI rather than one data point at a time. Although it is also possible to access it one-by-one by looping through as you are attempting to do. If you want to keep your AFL code simple, learn and use the data array directly as far as possible. You may not find it easy to begin with but once you get a hang of it you will start appreciating it. Lookup for AFL code samples in the AFL code library or AFL help itself.
Hope the above information helps you becoming an expert in AFL soon.
Cheers
Curious_Trader
Hope the above information helps you becoming an expert in AFL soon.
Cheers
Curious_Trader