Hello all and sorry for such a beginners question i guess, but ive forgot how to do this and i cant easily find an answer by searching words for this so im just going to ask:
How can i code: If there has been no crossover/crossunder on the moving average, for the past 20 bars, then K = 0
x = moving average 20
I could say: Close > x and close[1] > x[1] ……. close[20] > x[20]
and then reverse the < sign, but i know theres an easier way to write this piece of the code.
Big thx for any help.
Hello,
you are talking about “no cross” moving average I guess.
You can find a code snipet here :
Codage non croisement de moyennes mobiles
Hello,
you are talking about “no cross” moving average I guess.
You can find a code snipet here :
https://www.prorealcode.com/topic/codage-non-croisement-d-mm/
Thanks, i think its the “summation” part i was looking for 🙂 Looks like my code is working now, here it is for anyone wondering:
i have e1 and e2 = 20 at the moment, but you can try whatever numbers you want.
Im going to use this as a filter for when “price is choppy”. As soon as there has been e2 periods (20 at the moment) with no crossover/crossunder, then K=0.
x =exponentialaverage[e1](close)
once k = 0
if close crosses over x or close crosses under x then
k = k+1
endif
if summation[e2](close > x) then
k = 0
endif
if summation[e2](close < x) then
k = 0
endif
return k
You must know the rules by now jebus89! Topics must have meaningful titles – I’ve changed yours from ‘Simple question’!