How to know how many bars overall the SMA 200 was above the price from our current bar?

 

How to know how many bars overall the SMA 200 was above the price from our current bar?

Very simple but yet so complicated.., i just want to know the way to know how many bars in total the SMA 200 was above the price from the current open bar...

please help, thank you for your time!..

 
Loop from last bar towards first comparing SMA200 and price, for example close.
 
Create a timestamp at the sma cross. Now use this timestamp in the iBarShift function

Reset of timestamp would require at opposite cross or at some other criteria based on your objective.
 
kypa:
Loop from last bar towards first comparing SMA200 and price, for example close.

maybe could you show me an example please?

 
done!, thanks