Assuming your question is for MQL5 and you have not posted in the wrong section, then read the following for more information on making sure the information is updated and in sync.
Thank you for your answer, but it's mql4.
I indeed opened the topic in the wrong category, but the question is still valid.
If however, you did post in the wrong section, then ...
Forum on trading, automated trading systems and testing trading strategies
Clarifications for Pre-defined Variables
William Roeder, 2023.09.14 14:23
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Hi
On mt4 the data is not automatically updated on other timeframes that are not active charts. So, you might have to “force” refresh of the history.
You can try to get the data in a loop if the current time is updated, but I don’t know if this would be a good solution for your needs:
bool RefreshCandles(int _TF) { datetime DTArr[]; ArrayCopySeries(DTArr, MODE_TIME, Symbol(), _TF); int error = GetLastError(); if (error == ERR_HISTORY_WILL_UPDATED) { for (int i=0; i < 10; i++) { if (IsStopped()) break; Sleep(1000); } return (false); } if (_TF == PERIOD_CURRENT) _TF = Period(); if (TimeCurrent() - iTime(NULL, _TF, 0) >= _TF*60) return (false); return (true); }
Have a nice day👍📊
Thank you, I will try it.
Right now, I am trying to open a chart for every symbol and every timeframe, and keep redrawing it until all the candles are fully loaded. But this is quite cumbersome and really highlights the system's shortcomings.
-
No need for multiple charts. Just trigger an update for the symbol/TF you need:
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019) -
I recommend: Do not trade multiple currencies in one EA.
-
You can't use any {MT4: predefined variables, MT5: predefined variables,}
-
A multi-asset EA runs in one thread so that one asset blocks all the others, while each EA for a single asset runs in its own thread,
-
Must poll (not OnTick, unless you use specific indicators)
The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (2011) -
and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2 (2016)
-
You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}
-
Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.
Then put it on other charts to trade the other pairs. Done.
-
-
No need for multiple charts. Just trigger an update for the symbol/TF you need:
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019) -
I recommend: Do not trade multiple currencies in one EA.
-
You can't use any {MT4: predefined variables, MT5: predefined variables,}
-
A multi-asset EA runs in one thread so that one asset blocks all the others, while each EA for a single asset runs in its own thread,
-
Must poll (not OnTick, unless you use specific indicators)
The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (2011) -
and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2 (2016)
-
You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}
-
Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.
Then put it on other charts to trade the other pairs. Done.
-
Thank you for the reply, but I’m coding an indicator, not an expert. I’m building a dashboard indicator, so I need updated data for that.
Another question: have you ever experienced an indicator working well without issues, but then, after minimizing MT4 and bringing it back after a long time, the indicator’s previous signals jump forward to the current candle, completely disrupting the chart view?
When I restart the indicator, everything redraws to its proper place. When the signals are incorrect, if I hover over a bad signal, there is no value in the Data Window.
This is how I define the starting index of the candle for the for loop:
int limit = (int)MathMin(Bars - 2, MathMax(rates_total - prev_calculated, 0));

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Support, I have a technical question. If an indicator automatically uses higher timeframe candles (for example, M1 chart uses M15 candles, M5 chart uses M30 candles, etc.) and the indicator runs on a chart where I change the chart symbol to one that I loaded a long time ago, even though I can see the latest M1 candles on the chart (with correct datetime), the M15 candle series is not updated (it shows old candle datetime at 0. index). How can I ensure that the higher timeframe candle data is refreshed?
I don't want to provide a specific example, it's enough to demonstrate the issue by printing the time of the 0. candle on every tick.
Thank you in advance for your reply.