![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Thanks, that's spot on. Does the terminal really give a 4066 error after accessing an unupdated timeseries via iTime? I've encountered iClose giving unupdated information instead of zero.
That's the thing, that's the key point that's causing your hitch.
Error 4066 - when there is no history for this TF, it is not ready, you need to contact the server.
And when you already have it, but it is updated only when you access it, ie, does not give an error, just give you what is now, and simultaneously with the request begins to update the time-series.
If you access it infrequently and irregularly, sometimes you get old stuff. If you request each necessary TF regularly, up to each tick - then everything is OK.
If the chart of this TF is open, it is regularly updated on the chart. By the way, it is probably possible to open charts of all necessary TFs from EAs, if the access is not regular, but it is unreliable, because they can close/change TFs manually.
Why add 0 to [i + 0] ?
instead of zero I substituted 1 and 2, 1 or 2. I left 0, i.e. 1 bar. I haven't cleaned up the code, it's not important for logic.
That's the point, it's the key point that's causing you to get stuck.
Error 4066 is when there is no history for this TF, it is not ready, you need to contact the server.
And when you already have it, but it is updated only when you access it, ie, does not give an error, just give you what is now, and simultaneously with the request begins to update the time-series.
If you access it infrequently and irregularly, sometimes you get old stuff. If you request each necessary TF regularly, up to each tick - then everything is OK.
If the chart of this TF is open, it is regularly updated on the chart. By the way, it is probably possible to open charts of all necessary TFs from EAs, if access is not regular, but it is not reliable, because they can close/change TFs manually.
When there should be an error it gives back the old data, great. This is one of the reasons why brokers love MT4 and do not switch to MT5)).
I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?
When it should get an error it gives back the old data, great. This is one of the reasons why brokers like MT4 and do not switch to MT5)).
I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?
Almost. Here is a ready function:
Insert it in OnTick() and, if it returns true, the eTF timeframe can be accessed, the data is valid.When there should be an error it gives back the old data, great. This is one of the reasons why brokers like MT4 and do not switch to MT5)).
I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?
Of course, it is better to use sleep only in OnInit, and it is necessary only in indicators. In other cases, OnTick, as Igor mentioned above, is enough.
Depending on the task, you can manoeuvre your way to the best option. Usually, when checking if there is a new bar, iTime is already accessed on every tick for all used timeframes, which is enough to keep them up to date.
s.w. And if you use Igor's function not on every tick, but on some rare conditions, there will also be a lag.sleep is better used only in OnInit, of course, and it is only needed in the indicators. In other cases, it is enough to use OnTick, as Igor mentioned above.
Depending on the task, you can manoeuvre your way to the best option. Usually, when checking if there is a new bar, iTime is called at every tick for all used timeframes, it is enough to keep them up to date.
s.e. And if Igor's function is used not on every tick, but on some rare conditions, it will also be out of sync.Sleep does not work in indicators
Almost. Here's a ready-made function:
Insert it in OnTick() and if it returns true, you can access the eTF timeframe, data is valid.It's brilliantly simple. Thank you. Why don't the developers describe this in the manual on the iClose functions etc?Or correct the logic of MT4 quote updates so as not to create conspiracy theories.
When there should be an error it gives back the old data, great. This is one of the reasons why brokers like MT4 and do not switch to MT5)).
I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?
In MT5 it is much more difficult.
In F4 it is enough to request iTime from all used TFs every 2 minutes, and all data will be actual.
Everything is brilliantly simple. Thank you. Why don't the developers describe this in the manual on iClose functions and so on?Or correct the logic of MT4 quote updates so as not to create conspiracy theories.
Because almost all EAs do checks for the right conditions on every tick and everything updates by itself.
Sleep does not work in indicators
It works if you really need it :)
In MT5 it is much more complicated.
In 4 it is enough to request iTime from all used TFs every 2 minutes, and all data will be actual.
Exactly