Is there a way to know if two MA’s crossed within the lasts 120 candles?
Please update your country flag in your profile. Thank you 🙂
You can make a test with a summation of successful boolean condition:
test = summation[120](ma1 crosses over ma2)>0
If test returns “1”, it is true that a moving average crossover has occurred within the last 120 candlesticks.
I came up with…
// No trade during consolidation
if (MA200 crosses under MA400) or (MA200 crosses over MA400) then
noTradeBar = barIndex[0]
noTrade = 1
endif
if (noTradeBar + 120 < barIndex) then
noTrade = 0
endif
graph noTrade
But your code looks a bit more compact 🙂 Going to try it out. Thanks!