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

 
Alain Verleyen:
It doesn't work because the global variable is emulated with MT5 Tester. They also use TimeCurrent ().

Sorry, confused with MT4. Works in MT4, but not MT5.

 
fxsaber:


Application


HH Is there an easier way to find out the local time of the computer in the Tester?

It's not rational in this way. You need to get the real time only once, and then calculate the difference using GetTickCount or GetMicrosecondCount.

 
Alexey Navoykov:

You need to get the real time only once and then calculate the difference using GetTickCount or GetMicrosecondCount.

Yes, I agree.

 
And the code?
 
Alexei Tarabanov:
And the code?
 
Alexey Navoykov:

You need to get real time only once and then use GetTickCount or GetMicrosecondCount to calculate the difference.

The time density in the tester is completely different. It won't work.

 
Alexei Tarabanov:
And the code?

Updated.

 
fxsaber:

Updated.

GetTickCount should consider overflow
 
TheXpert:
In GetTickCount overflow should be taken into account

If you subtract another UINT from one UINT, the result will always be correct, even if there is an overflow.

Illustration

void OnStart()
  {
//---
   uint first=UINT_MAX-5;
   uint second=first+100;
   PrintFormat("%u - %u = %u",second,first,second-first);
  }

log

2018.10.18 10:48:12.775 TestUint (EURUSD,M1)    94 - 4294967290 = 100
 
Slava:
If you subtract another UINT from UINT, the result will always be correct, even in case of overflow.

Probably, it meant that one pass can last longer than ~50 days (then GetTickCount goes through full cycle). But that's out of the realm of practice.