My quick impression is that the original code here was written with the implicit assumption that "the platform" would be executing it "on every bar".
This is the mental paradigm one develops after working with, say, EasyLanguage, for a long period of time. However, it is not the right mindset for AFL (at least, that's my opinion at this point) When working with AFL, I would suggest thinking of "all these arrays" just sitting there in memory, and a program that will execute just once (not on every bar). Is this actually correct? I don't know, and I have yet to find documentation on the actual execution model that AFL operates under. What I can say is that my ability to get AFL to do what I intended quickly improved once I adjusted my thinking in this fashion.
