Can not get accurate current price.

 

Hi,

I am a newbie learning to write EA. here are the problem, can any one help?

My logic is when MA3 more than MA8, then buy. when MA3 less than MA8, then sell. below is the code.I base on hourly chart.

douMA3Current = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,0);
douMA3Previous = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,1);
douMA8Current = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0);
douMA8Previous = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,1);
sendMessage(StringConcatenate("ma3C ",DoubleToStr(douMA3Current,4)," ma8C ",DoubleToStr(douMA8Current,4),"ma3P ",DoubleToStr(douMA3Previous,4)," ma8P ",DoubleToStr(douMA8Previous,4)));
booBuy = (douMA3Current > douMA8Current && douMA3Previous < douMA8Previous);

I can get accurate Previous MA price, but my Current MA price is different from the chart. Can any one help?

Thank you

Fxcheong