Sorry if there is a topic discussing this, but I couldn't find such one. I am also waiting for an answer from Meta Quotes... I will paste the question here too.
For the purposes of our robots, we need to be able to work with latest rates at any given moment, otherwise we may take wrong decisions.
Let's use the following code:
int size = CopyRates('NZDUSD', PERIOD_M15, StringToTime("2016.11.01 13:00"), TimeCurrent(), rates);
- Is it possible CopyRates to return data with holes? (e.g. 13:00, 13:15, 13:45 - note 13:30 is missing)
Might be TimeLocal() is better for the example, given that TimeVurrent() returns the time of the last but you get what I mean.
What's the right way to make sure CopyRates returns exactly what is requested?
Or an alternative question might be... Is there a way to get the time when the rates were last synced with the server? We can compare that time with TimeLocal() and if the difference is big, just do not trade at that time.
That can be simulated by turning off the network for a while.
Functions in https://www.mql5.com/en/docs/marketinformation do not really help because no of them seems to return error if network is disconnected.
SymbolIsSynchronized was promising, but I doesn't seem to work... SymbolInfoTick might be of some help but when it returns the last tick and it is not changed, we can't say if the tick was just not updated on the trading server or data is not synced and that's an important difference.
You get whatever the terminal has.
What do you do if there has been no ticks for the last couple of minutes, such as during the Asian session? "Free-of-Holes" Charts - MQL4 Articles
You could remember TimeLocal when you receive a tick and can then check, but why bother. No tick, nothing has changed. You already processed that tick, what would you do now?
@whroeder1, that's different.
If you don't have ticks that's just fine, you have the latest data, so it's up to your algorithm to decide what to do (as you say nothing changes, nothing to do).
Imagine you have ticks1 t1,.....,t100 on the trading server, but the terminal has lost connection for a while and you have just ticks t1,...,t5 on the terminal. Taking decisions based on t1,...,t5 might be completely wrong. Moreover the prices you are going to use for your orders may be completely irrelevant.
Keeping time of the last tick does not help. And the reason is that you don't know if the last tick is the last one on the trading server or you just got disconnected.
"No tick, nothing has changed. You already processed that tick, what would you do now?"
That statement is not correct for what I ask. There are new ticks, the terminal just didn't receive them because of connection issues. In that case we should get an alert and understand why we have connection issues. Best brokers should almost never have connection issues, but if there are, then we may want to stop the robot or do some other mitigation. (we've had a similar problem recently - ~24 hours connection issues because of issues on the broker's side - which corrupts the strategy for that period)
Hopefully this makes sense.
Thanks @whroeder1 for spending the time, trying to help.
It's enough to know the last time when rates in terminal and the ones on the trading server are in sync. That's absolutely easy if MT5 keeps a timestamp of that and exposes it through an API. That's what I asked Meta Quotes and what I asked here.
That's a robot and moreover unattended, sounds do not help in these scenarios. We have a much more complicated monitoring system that we integrate with the robot. But its integration is not a problem, the lack of the right event is the problem.
What you suggest is a partially-working solution which I have mentioned in the end of my initial post... but this is not working good enough... It might be simply the case when you have no ticks ... in this case the difference might be X seconds from last tick but this does not mean disconnect. I want to distinguish failures.
I can detect the message "lost connection" in the log, but I am not sure it's absolutely reliable. I was hoping that there might be an API for that.
After researching a bit...
I found a property TERMINAL_CONNECTED (https://www.mql5.com/en/docs/constants/environment_state/terminalstatus) which becomes 0 ~15 secs after the network disconnection.
That can be used for handling if the connection is lost. If there is connect/reconnect for less than 15 sec, we won't be able to handle the connection problem this way. However, we can use CopyTicks to find if ticks have been missed for a few sec. That would help evaluating a broker.
@whroeder1 thanks again for your help.