However, I am looking for a more AFL way of doing this using vector processing, as I believe it will be atleast 10X faster. I am trying the following code but it gives undesired result
I know the above line won't work because Ref(x, -1) will just create a new array first, while I am trying to use this array in a recursive sense (created bar by bar sense as in the loop).
Please help me with a vectorised code for achieving the same result as the loop code.
Thanks in advance.
and ValueWhen will be something like 30-50x faster than loop. Your loop can be replaced by single function call that not only is shorter but also much cleaner than loop and reads like plain English sentence:
"give me the VALUE of Close WHEN Close was higher than Open"
LastGreenCLose = ValueWhen( C > O, C ); // that is easy and straightforward one-liner
So array code is actually easier to write than looping code if you just stop thinking in "obsolete" looping terms and starting thinking on the concept level (what this code actually does).