Order of EMA crosses

 

Hi,

I am trying to develop a code that identifies the order in which EMA crosses happen. For eg. I have 3 EMA's : 5, 8, & 14. I want to get an alert when EMA5 crosses EMA8 first and then crosses EMA14 (in that order). All these crosses must happen within a specified number of bars, say 5. Rules are the same for upward or downward crosses.

How would I go about coding this please?

Thanks

Gc

 
You really don't care when, only if ema(5)>ema(8) && ema(8) > ema(14)
 

Right, I care for the order of the crosses, not the actual time when these crosses happen. As long as these crosses happen within the specified number of bars, it should be fine.

Btw, it is ema(5)>ema(8) && ema(5) > ema(14).

I mean, ema(5) crosses ema(8) first. After say 4 bars, ema(5) crosses ema(14). This is considered to be a valid setup.

 
for (int emaCross=0; emaCross < 100; emaCross++){
   double ema5 = iMA(NULL,0, 5, 0,MODE_EMA,PRICE_Close, emaCross  ),
          ema5p= iMA(NULL,0, 5, 0,MODE_EMA,PRICE_Close, emaCross+1),
          ema8 = iMA(NULL,0, 8, 0,MODE_EMA,PRICE_Close, emaCross  ),
          ema8p= iMA(NULL,0, 8, 0,MODE_EMA,PRICE_Close, emaCross+1);
   if ( (ema5-ema8)*(ema5p-ema8p) <= 0 ) break;
}
 
Thanks a lot WHRoeder, appreciate the prompt response.
 
what are EMA?
 
Reason: