Hi,
I’m using two exponential moving averages (30EMA and 50 EMA). My question is how do I code to check the distance between the 30EMA and 50EMA is less than 20 PIPS over the last 20 bars, and the 30 EMA has remained above the 50 EMA over the same period, i.e. last 20 bars?
Do the distance must be strictly less than 20 pips during all the last 20 bars?
Ideally I want to be able to control the distance between the two EMA’s, 20 PIPs was an example. The main aim is not to see the two ema’s drift wider and wider apart.
So this code should do the test for you:
testperiod = 20 //number of bars for the test
distance = 20 //distance in points between the 2 EMA
ema30 = exponentialaverage[30]
ema50 = exponentialaverage[50]
test = summation[testperiod](ema30>ema50)=testperiod and summation[testperiod](ema30-ema50<=distance*pointsize)=testperiod
return test