You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Look again here.
The first request is your loop that you decide not to talk about:
The first request generates an error, but you don't check for it.
The second request is your attempt to see the error after the loop:
No more error!
Look again here.
The first request is your loop that you decide not to talk about:
The first request generates an error, but you don't check for it.
The second request is your attempt to see the error after the loop:
No more error!
Instead of making stuff up, here's the real code:
There is never any error.
Why is the error not generated?
Because that's how the terminal works.
Possibly due to calling iTime() with different parameters between repeated first and second requests:
But most likely, even without this, the error can also stop being generated.
The error will be generated at the moment the history starts to load. But you cannot be sure that the error will be generated during the whole history loading time.
How can one symbol have a different server time than all the others?
Instead of making stuff up, here's the real code:
There is never any error.
If you are accessing non native (the operating chart) price + time data you have to anticipate errors .
If you are not working with the native chart , as @Vladislav Boyko indicates , the first call usually tells the terminal to go fetch , so you must be running checks
for whether or not there is a new bar formation based on server time and that symbols server time .
If its in the market watch its last tick time is logged so if you pick up a distance in iTime(...,...,0) to its last tick bigger than PeriodSeconds() you know
it is not providing you with the latest bar.
I have never encountered it from this side (the right side) but in several scanners (in MT4) to make sure data was loaded properly i would open charts and
navigate in the past to expedite the download of data .
It helps if you think about it from the perspective of the terminal .
Edit : observe this EA screen comments for a while :
Bars are not late.
You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed, and that tick could arrive almost at the end of a bar's duration.
Do not assume every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)
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)
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)
Suppose still 4066/4073 is not resolved. What do you do? Just wait in a loop until it is resolved? Or exit the indicator with a error message?
Suppose still 4066/4073 is not resolved. What do you do? Just wait in a loop until it is resolved? Or exit the indicator with a error message?
In MT4 you exit , if a chart has never been opened -in MT4- it may require a manual open before it can receive data .
Suppose still 4066/4073 is not resolved. What do you do? Just wait in a loop until it is resolved? Or exit the indicator with a error message?
This means that you cannot use historical data until it is loaded by the terminal.
Just wait.
in a loop
Not in a loop. Your program should be designed to accommodate situations where historical data is not available. Historical data is needed for some kind of action. While this data is in the process of loading, the program should not perform actions that depend on historical data.
For example, the program has an entry signal generation block that uses historical data, and a trailing stop that does not require historical data. As long as historical data is not available, the entry signal generation block generates "no signal", and the trailing stop continues to work normally.
The issue of determining the moment when the loading of historical data in MT4 is completed does not have a simple solution. Personally, I wait 30 seconds and 10 ticks from the moment I receive a history access error. That is, if a history error occurred within the last 30 seconds or within the last 10 ticks, my code does not use the history. But I request all used charts with each tick, in order for the terminal to keep them up to date. Thus, my MTF EAs often start work 30 seconds late (from the moment of attachment), but thanks to the request of all charts with each tick, history errors no longer occur.