Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Millions of traders are waiting for this!
ale 2015.07.11 09:39 

Is it possible to read the value of a EMA as it was at a certain point in the past, while the bar was still forming?

For example, it is 16:05 and I am on TF M5. I would like to know what was the value of H1 EMA(20) at 14:35. Using iMA + iBarShift(14:35) will return the EMA for the now-closed H1 bar 14:00 to 15:00. But the value at 14:35 is not the same value as the value when the bar has closed.

Is there a way in MQL4 to retrieve that value or should I reimplement my own EMA function?

ydrol 2015.07.11 10:59  

Option 1: At every M5 candle - compute H1 EMA and store for later. (caveat see below)

Option 2: Or re-implement MA by reading data from M5 and rolling it up to be H1 data but with candle open times 13:35, 12:35, 11:35 etc.   

Option 3. Step down one timeframe - the result will not be the same - but might be close enough for your strategy. - eg  instead of H1  EMA(20) use M30 EMA(40).  

Probably other options too..


Caveat: If using H1 candles direct from history centre be careful reading MA of open candles - I haven't checked but I suspect they may not give you the expected results. Imagine H1 SMA(2) - a simple MA based on the last two hours.

time 12:00:00 Price 1.1

time 13:00:00 Price 1.1 | SMA(2) = 1.1

time 14:00:00 Price 1.3 | SMA(2) = 1.2  (1.1+1.3)/2

time 14:00:01 Price 1.3 | SMA(2) = 1.3 (1.3+1.3)/2    <-- this partial 1 second open candle contributes as much as each closed 1 hour candle. (I suspect)

To add comments, please log in or register