iTime is the start time of the reference candle. In your case (H1/0,) top of the hour. After the start of a new candle, TimeCurrent will be increasing.
There should never be a 2 hours difference. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073
errors before accessing candle/indicator values.
Download
history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
iTime is the start time of the reference candle. In your case (H1/0,) top of the hour. After the start of a new candle, TimeCurrent will be increasing.
There should never be a 2 hours difference. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073
errors before accessing candle/indicator values.
Download
history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
Thank you for your answer.
But why it (the error) happen only at 00:00? While at the other hours it is working normally. So at that time the iTime and TimeCurrent have (or print) the same time exactly.
Hello @William Roeder,
I use the code in the link above, but it still have the same problem.
#property copyright "" #property link "" #property version "1.00" #property strict #define SYMBOL string datetime timer=0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- EventSetMillisecondTimer(500); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(IsTesting()) OnTimer(); } //+------------------------------------------------------------------+ void OnTimer() { //Check history while(!download_history(PERIOD_H1)) { Print("Failed to download history of Period H1"); Sleep(1000); RefreshRates(); } //check next session datetime hour_now=iTime(Symbol(),PERIOD_H1,0); if(timer!=hour_now) { Print("Hour now = ",TimeToStr(hour_now),", Current Time = ",TimeToStr(TimeCurrent())); timer=hour_now; } } //+------------------------------------------------------------------+ bool download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT) { return download_history(_Symbol, period); } //+------------------------------------------------------------------+ bool download_history(SYMBOL symbol, ENUM_TIMEFRAMES period=PERIOD_CURRENT) { if(period == PERIOD_CURRENT) period = (ENUM_TIMEFRAMES)_Period; ResetLastError(); datetime other = iTime(symbol, period, 0); if(_LastError == 0 && other != 0) return true; if(_LastError != ERR_HISTORY_WILL_UPDATED && _LastError != ERR_NO_HISTORY_DATA ) PrintFormat("iTime(%s,%i) Failed: %i", symbol, period, _LastError); return false; } //+------------------------------------------------------------------+
And I had a result like this :
When it is initialized,
Hour now = 2019.11.01 22:00, Current Time = 2019.11.03 22:22.
It means that when it print the journal, the Market Watch = 2019.11.03 22:22. So, the time for the H1 candle should be 2019.11.03
22:00, right? Then it has 2 days different.
Hello @William Roeder,
I use the code in the link above, but it still have the same problem.
And I had a result like this :
When it is initialized,
Hour now = 2019.11.01 22:00, Current Time = 2019.11.03 22:22.
It means that when it print the journal, the Market Watch = 2019.11.03 22:22. So, the time for the H1 candle should be 2019.11.03
22:00, right? Then it has 2 days different.
Thank you @Alain Verleyen,
I think I will try to use OnTick and see the difference.
I still get the same result.
Looks like I have to find the other way.
I still get the same result.
Looks like I have to find the other way.
Show your code.
What broker and symbol are you using ?
Show your code.
What broker and symbol are you using ?
It was my fault.
The problem is my Start Time and End Time.
I just realize that when I set the Start Time 00:01 --> it is based on my local computer time, and the fact is that the Market watch is 5 hours
behind me.
This cause error for every new day (of my computer time), while the Market is still 1 day behind, that is why I missed the last 5 hours of the H1 candle.
I just found this yesterday and test it all the night and it is working good.
Thank you!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I have a case :
Here is mycode
Then at 00:00 I have a result :
Hour now = 2019.10.29 00:00, Current Time = 2019.10.29 02:00
How come they have 2 hours difference at the same time?
This happened at 00:00 only. At the other hours, working good.
Anyone can help me?
Thank you