Best way to make action only once

Buba Akhrakhadze
Buba Akhrakhadze  

Hi, I used timestamp to make action only once before, but I noticed that it isn't that accurate and when action happens more than 2-3 times per second it happens 2-3 times too I mean tick change per second. Below is my code that I used before:

   int AlertCount = 0;
   static datetime TimeStamp;
   if(TimeStamp != Time[0])
    // Some actions here
   TimeStamp = Time[0];

has anyone knows better way to make action only once?

William Roeder
William Roeder  
Buba Akhrakhadze: has anyone knows better way to make action only once?
  1. Time has a resolution of one second. So your condition plus time is valid for all ticks withing a second.
  2. You are looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

Dominik Egert
Dominik Egert  
You could use GetTickCount64() as a serial number for your actions next to the timestamp.

This gives you a resolution of 1 ms.

And if that is not enough, use GetMicrosecondcount().

That's a microsecond resolution.