As you might know, whenever you call something like CopyRates or iHigh on a Symbol that doesn't have an open chart set to that Period, you will either get old data or an error value.
However, MT4 will update the history data for that Symbol + Period and it can be accessed shortly thereafter.
My question is, if you need the current history data on a symbol that doesn't have a chart open on that period, how are you handling this?
I've brainstormed some ideas and so far I think it's best to call, say, iHigh for all the required Symbol+Periods that don't have an open chart, then call EventSetTimer with a value of 10 seconds. When 10 seconds has expired, then run the rest of my program that requires the up-to-date history data, and call EventKillTimer.
If there's a better way to do this (making sure to have access to current history data for Symbol+Periods that don't have an open chart), I'd love to hear about it.
Thanks.
In Multi-Symbol/Multi-Time-frame Indicators and/or EAs, you have to properly handle the synchronisation of the requested of data on a timely fashion by handling 4066/4073 errors. Failure to do this will cause it not to work properly.
Forum on trading, automated trading systems and testing trading strategies
Minimum requirements for showing different symbol info in-time info in one chart?
William Roeder, 2021.08.27 17:06
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 - Forex Calendar - MQL4 programming forum - Page 3 #26.4 (2019.05.20)On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020.12.15)
Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019.05.31)
Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum #2 (2018.07.17)
SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019.09.03)
In Multi-Symbol/Multi-Time-frame Indicators and/or EAs, you have to properly handle the synchronisation of the requested of data on a timely fashion by handling 4066/4073 errors. Failure to do this will cause it not to work properly.
Alright, after reviewing the threads, it seems that the proper way to wait for the updated history data is:
- For Scripts/EAs: use Sleep for a certain period of time and keep checking if the history has been updated (by checking for errors and correct time)
- For Indicators: return prev_calculated in OnCalcualate until history has been updated (by checking for errors and correct time)
I'm not a fan of return prev_calculated since that spams OnCalculate and, thus, would spam the history check.
Since I'm writing an indicator, I think I'll stick with EventSetTimer/EventKillTimer as described in my OP.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
As you might know, whenever you call something like CopyRates or iHigh on a Symbol that doesn't have an open chart set to that Period, you will either get old data or an error value.
However, MT4 will update the history data for that Symbol + Period and it can be accessed shortly thereafter.
My question is, if you need the current history data on a symbol that doesn't have a chart open on that period, how are you handling this?
I've brainstormed some ideas and so far I think it's best to call, say, iHigh for all the required Symbol+Periods that don't have an open chart, then call EventSetTimer with a value of 10 seconds. When 10 seconds has expired, then run the rest of my program that requires the up-to-date history data, and call EventKillTimer.
If there's a better way to do this (making sure to have access to current history data for Symbol+Periods that don't have an open chart), I'd love to hear about it.
Thanks.