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:
1
lookback=20//20 bars lookback
Then define the conditions you’d like to be tested through this lookback period:
1
c1=average[7]crosses overaverage[21]
Finally, count how much time this “c1” condition returned true (so condition value would be 1) in the past with the summation instruction:
1
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
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue