I found one indicator in this forum for EMA crossing, it is called the "DoubleMA". However, the code is too complicated for me to understand. I need to abstract the formula for the code so that I may use it to develop a code that suits me.
The out come of my EMA crossing formula looks OK. Somehow the formula is always one bar behind (slower) when compare to "DoubleMA". I wonder why. So I attached here my formula in hope that somebody can give some help:
for (int idx = Math.Min(CurrentBar, Ema_fast - 1); idx >= 0; idx--)
fasterEMAnow= EMA(Close, Ema_fast)[0];
fasterEMAprevious= EMA(Close, Ema_fast)[+1];
slowerEMAnow=EMA(Close,Ema_slow)[0];
slowerEMAprevious= EMA(Close, Ema_slow)[+1];
//Actual formula for EMA formula
if ((fasterEMAnow > slowerEMAnow) && (fasterEMAprevious < slowerEMAprevious) )
{ trend = 50; }
if ((fasterEMAnow < slowerEMAnow) && (fasterEMAprevious > slowerEMAprevious))
{ trend = 25; }
Ema_plot.Set(trend);
I wish to know why my code is always one bar slower????? Thanks!!!
shek
Comment