Finding 2nd last event that occurred ?

 

Hey,

I've been trying to find if there is a way of retrieving the second last time a particular event occurred.

An example could be that a green candle forms. Is there anyway of retrieving the high of the last green candle that formed before this one. Assuming the sequence was red, green,red,red,red,green.

So i am not looking at just the previous candle as that would be red but want to recall the high of the last green which is the 5th bar back. However the length can obviously vary depending on when the next green would be plotted so i don't want to use "search for last green over last 20 candles" it is a bit messy.


The function exists within iFractals you can recall a fractal x amount of times back but can it be done with your own event such as the last time a green candle plotted 


I hope that makes sense 

thanks in advance for any help 

:)

 
Use a simple while loop and check back through the bars until you find what you want, then break the loop.