iMA mismatch values

 

I'm new to MQL4.  Trying to use iMA in an EA to identify HA close cross a MA on bar 1.  It compiles with no errors and no exceptions.  Here's the logic and code lines:


(HAClose1>MAH1)


HAClose1=(Open[1]+High[1]+Low[1]+Close[1])/4;

MAH1 = iMA(NULL,0,SMMAperiod,1,MODE_SMMA,PRICE_HIGH,1); 

//I tried using ma_shift of 0, but makes no difference in EA function and backtest result.


The problem is that the EA action does not match the observed crosses on the price chart.  That is, the bar closes, and the HAClose is above the MAH1 value on the graph line...but the EA does nothing.


Thanks for help.


comdoc 

 
You are referencing Bar[1]. The current bar is Bar[0] (the last bar on the left of the chart). That might be your problem.
 
jmca:
You are referencing Bar[1]. The current bar is Bar[0] (the last bar on the left of the chart). That might be your problem.

How can there be a close value on current bar 0?  My understanding is that current forming bar on extreme right of chart is referenced as bar 0.  Only HA open value is stable on bar 0.  Yes?

 
Close is the last price tick. The bar does not need to be finished for the close to exist. Look at the data window. When referencing Bar 1 you are talking about the past. If that's what you want that's fine, but if you're looking to gear towards the current price action, Bar 0 is what you use.
Reason: