Hi,
I’m trying to count the number of times a short moving average crosses over or crosses under a long moving average over a number of bars. Any help would be gratefully received.
Hmmm this question of “how much time something occurred in the past through x bars ” have been asked many times. I assume I should make a video for this 🙂
So firstly, you have to define how much bars you want to lookback:
lookback = 20 //20 bars lookback
Then define the conditions you’d like to be tested through this lookback period:
c1 = average[7] crosses over average[21]
Finally, count how much time this “c1” condition returned true (so condition value would be 1) in the past with the summation instruction:
x = summation[lookback](c1)
Now you have your variable x which contain the number of times the condition “c1” occurred through “lookback”. Happy testing.
Nicolas thanks – and apologies. I assume if had looked harder I would have found the answer in your other posts. Really good of you to help me out and very much appreciated. Nick