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

 
fxsaber:
A nuance of comparing integers on a real example

Are you going to measure exactly one second with Sleep(1000)?

And the fact that the timer in the processor has an error of 15 ms, don't you know it?

 
Slava:

Are you going to slip Sleep(1000) to measure exactly one second?

Didn't you know that the timer in the processor has an error of 15 ms?


Hello, could you please tell me if there is a way to reset the timer buffer to eliminate the timer setting error?

 
Vladislav Andruschenko:

Hello, could you please tell me if there is a way to reset the timer buffer to rule out a timer setup error?

The timer setup error occurs because the system message queue is full. There could be many reasons for this. Usually it's only temporary (if it's not temporary you won't be able to work on your computer)

Use OnTick to control the timer. If the timer is not set, set it in OnTick

Meanwhile we are working on making the timer settings independent from the state of message queue.

PS Allowing the system timer and setting the timer for an application are not related to each other

 
Slava:

Are you going to use the Sleep(1000) slip to measure exactly one second?

No, I'm talking about these two lines of integer comparison.

Forum on trading, automated trading systems and strategy testing

Features of mql5 language, subtleties and tricks

fxsaber, 2018.01.24 21:48

The nuance of comparing integers on a real example
//  if (GetMicrosecondCount() > StartTime + 1000000) // Неправильно
  if (GetMicrosecondCount() - StartTime > 1000000) // Правильно

At first glance, both lines should give the same results. But this is not the case. The first one will sometimes give the wrong output.

The example with time is chosen only for clarity.
Slava:

And the fact that the timer in the processor has an error of 15 ms, is that unknown to you?

It's strange that you still use GetTickCount. It has been proven on the forum (I'm too lazy to search) that a microsecond timer doesn't slow down more than a millisecond timer. At the same time has a wild error.

 
fxsaber:

No, we are talking about these two lines of comparison of integers.

At first glance, both strings should give the same results. But they don't. The first one will sometimes give you the wrong result.

The example with time is chosen only for clarity.

It's strange that you are still using GetTickCount. It has been proven on the forum (I'm too lazy to search) that the microsecond timer doesn't slow down more than the millisecond timer. At the same time it does not have a wild error.

I mean Sleep(1000)
 
Slava:

The timer error occurs because the system message queue is full. There can be many reasons for this. As a rule, queue overflow is temporary (if it is not, you won't be able to work on your computer)

Use OnTick to control the timer. If the timer is not set, set it in OnTick

Meanwhile we are working on making the setting of the timer independent from the state of the message queue.

PS Enabling the system timer and setting the timer for the application are not related at all


That's exactly what I do,

The timer error occurs after some time - not immediately. and exactly because of the overflow - when there is a lot of data, for example order history, or current orders of 50 or more.

If i have a good working knowledge, i should try to use it as a base.

 
Slava:
I'm talking about Sleep(1000).

Yes, you're talking about comparing integers.

 
fxsaber:

Yes, you're talking about comparing integers.

There is no problem comparing integers.

Show the same thing without the slip and without GetMicrosecondsCount

 
Slava:

There is no problem comparing integers.

Show the same without slip and without GetMicrosecondsCount

ulong GetMicrosecondCount2()
{
  static ulong StartTime = 0;
  
  if (StartTime)
    StartTime += 1000001;            // При повторном - добавляем больше "секунды"
  else
    StartTime = ULONG_MAX - 1000000; // При первом запуске возвращаем это "время"
    
  return(StartTime);
}

void OnStart()
{
  const ulong StartTime = GetMicrosecondCount2();
  
//  Sleep(1000);
  
//  if (GetMicrosecondCount2() > StartTime + 1000000) // Неправильно
  if (GetMicrosecondCount2() - StartTime > 1000000) // Правильно
    Print("Прошло больше секунды.");
  else
    Print("Прошло меньше секунды."); 
}
And it's not a problem, it's a subtlety.
 

Forum on trading, automated trading systems and trading strategies testing

Discussion of the article "Hedging position accounting system added to MetaTrader 5"

fxsaber, 2018.01.25 10:14

  1. Shows an example of a trading situation that Andrew pointed out when reading this article.
  2. HistorySelectByPosition may not select the order that caused the trade.
  3. The order and the deal it spawned may have different IDs.
The second and third paragraphs should at least be voiced somewhere. Which I did.

We are talking about the analysis of the history of even manual trade, we are not talking about writing the TS.

For example, we want to understand how a deal slipped through.
Reason: