Features of the mql5 language, subtleties and tricks - page 74

 
Vitaly Muzichenko:

How to find out that there are no quotes because it is a day off, or for example on Thursday there are no quotes because the server hangs up in the dealing room?

It is possible to determine the fact that it is a day off by the local time.

And the GMTOffset calculation of the server should be done only in OnTick. As long as the tick has not come, do not use the server time in calculations. In most cases this is really not required.

As a last resort, if GMTOffset was required at the weekend, give a message to the user and, perhaps, ask for GMTOffset of the server from him.

 
GMTOffset on forex symbols can be determined by the closing/opening time of the trading week. After all, the local time of this event is known.
 
Ihor Herasko:

It is possible to determine the fact of the day off by the local time.

But the calculation of GMTOffset server should be done only in OnTick. As long as the tick has not come, do not use the server time in the calculations. In most cases this is really not required.

As a last resort, if GMTOffset was required on a weekend, give a message to the user and possibly ask for a server GMTOffset from them.

fxsaber:
GMTOffset on forex symbols can be determined by the closing/opening time of the trading week. After all, the local time of this event is known.

In our case on Saturday and Sunday we do not know the time of server, we only know the time of arrival of the last quote. Also we don't know in what timezone the server works.

Very much missing is a function that will show the current time of the server, something like: TimeServer(); then you can always know that the server time is higher than the time of the last quote, it means either the day off, or hung. GMTOffset doesn't save us.

P.S. The question concerns not only forex symbols.
 
Vitaly Muzichenko:

On Saturday and Sunday we do not know the time of the server, we only know the time of the last quotation. In which time zone the server works - is also not known.

For Forex it is solved, as I said above.

 
Vitaly Muzichenko:

We do not know the server time on Saturday and Sunday

I have known the local time.

We only know the time of the last quote. In which time zone the server works - is also not known.

Very much we need a function that will show the current time of the server, something like TimeServer(); then you can always know that the server time is higher than the time of the last quote, it means either the day off or hung up. GMTOffset does not save us.

If we know the local time, we don't even need to guess. Using it we can determine if it is a weekend or not. And knowing GMTOffset server just gives an opportunity to calculate the server time. I do not argue that the TimeServer() function would be useful. Nevertheless, even without it now we can get away with it.

 
Ihor Herasko:

For that, the local time is known.

Knowing the local time, you do not even need to guess. By it we determine whether it is day off or not. And knowing GMTOffset of server just gives possibility to calculate server time. I don't argue that the TimeServer() function would be useful. Nevertheless, even without it, you can get away with it now.

It's not server time.

Документация по MQL5: Дата и время / TimeGMTOffset
Документация по MQL5: Дата и время / TimeGMTOffset
  • www.mql5.com
Возвращает текущую разницу между временем GMT и локальным временем компьютера в секундах с учетом перехода на зимнее или летнее время. Зависит от настроек времени на компьютере пользователя.
 
Vitaly Muzichenko:

It's not the server time.

I'm talking about TimeLocal(). Naturally, we also need TimeGMTOffset. If it is ticking, then we have no problem calculating ServerGMTOffset. If the Expert Advisor has received at least one real tick, it will be able to calculate the current server time using TimeLocal().

The problem arises when the EA has started without a tick. In this case, you need to determine whether it is a weekend or not. If it is the weekend, all calculations related to the real server time will have to be postponed until the weekend is over. If it is so necessary to make calculations on the weekend, we ask the user to specify ServerGMTOffset. Get this data and use TimeLocal() and TimeGMTOffset() to get the current server time.

 
Ihor Herasko:

I'm talking about TimeLocal(). Naturally, we also need TimeGMTOffset. If there are ticks, then we have no problem calculating ServerGMTOffset. If the Expert Advisor has received at least one real tick, it will be able to calculate the current server time using TimeLocal().

The problem arises when the EA has started without a tick. In this case, you need to determine whether it is a weekend or not. If it is the weekend, all calculations related to the real server time will have to be postponed until the weekend is over. If it is so necessary to make calculations on the weekend, we ask the user to specify ServerGMTOffset. Having received this data and using TimeLocal() and TimeGMTOffset(), we obtain the current server time.

Exactly. Hang the Expert Advisor on the chart at the time of "no ticks". This can be anything, and even a day off.

The time of the last tick is 15 minutes ago (the EA does not know that, and neither do we), but what time is the server running at? Is it really 15 minutes ago, or maybe 1h.15m, or 3h.15m?

 
Vitaly Muzichenko:

Exactly. Hang the Expert Advisor on the chart during the "no ticks" period. This can be anything, even a day off.

The time of the last tick is 15 minutes ago (the EA does not know this, and neither do we), but what time does the server use? Is it really 15 minutes ago, or maybe 1h.15m, or 3h.15m?

Vitaly, the time zones differ from each other by at least 1 hour. More precisely, a multiple of 1 hour. Accordingly, if the difference is more than an hour, then something happened.

More specifically, you can get the difference between local and server time in OnInit, then compare this with the current difference. In general, the options are for fans.

 
Alexey Viktorov:

Vitaly, the time zones differ from each other by at least 1 hour. More precisely, a multiple of 1 hour. Accordingly, if the difference is more than an hour, it means that something happened.

More specifically, you can get the difference between local and server time in OnInit, then compare this with the current difference. In general, the options for the amateur.

I put the EA on the chart on Saturday; however, the EA may get the time of the last tick; for example, it is 23:58 in Market Watch and my local time is 04:45. The server time I do not know.

My question is: How much time has passed from the last tick to the server's (terminal's) time?

Reason: