ticks duration = 0 ?

 

Hi Everyone,

I've written a short code to measure the minimum duration between two ticks during a backtest (MQL4). I get one value =0ms: what could be the reason?

It happens on Dow Jones (US30 Fxcm on 12th November around 11:34).

Thanks a lot in advance :-)

Here's my code:


uint g_ttick_ms_prev, g_ttick_ms;

uint g_dttick, g_min_dttick_ms;

bool g_readytomeasuredttick;





int OnInit()

{

   

   Print("====================TEST 002 start=============================");

   g_ttick_ms_prev = 0;

   g_ttick_ms = 1e6;

   g_dttick = 1e6;

   g_min_dttick_ms = 1e6;

   g_readytomeasuredttick = 0;



   return(INIT_SUCCEEDED);

}



void OnTick()

{    

   if( g_readytomeasuredttick )

   {

      g_ttick_ms = GetTickCount();

      

      // get tick time

      g_dttick = g_ttick_ms - g_ttick_ms_prev;

   

      if( g_dttick < g_min_dttick_ms )

      {

         g_min_dttick_ms = g_dttick;

         Print("g_min_dttick_ms=",g_min_dttick_ms);

         if( g_min_dttick_ms==0 ) while(1);

      }

      

      g_ttick_ms_prev = g_ttick_ms;

   }

   else

   {

      g_ttick_ms_prev = GetTickCount();

      g_readytomeasuredttick = 1;

   }

     



}





void OnTimer()

{

   // stores prices every 1ms

   

}

     



void OnDeinit(const int reason)

{

   Print("====================TEST 002 stop=============================");

   Print("Final value g_min_dttick_ms",g_min_dttick_ms);

   

}

   







double OnTester()

{

//---

   double ret=0.0;

//---



//---

   return(ret);

}





void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)

{

   //counter++;

   //Print("Chart event" , counter);

}

//+------------------------------------------------------------------+


 
  1. Threepwood: I get one value =0ms: what could be the reason?

    The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.

              GetTickCount function (sysinfoapi.h) - Win32 apps | Microsoft Docs

    You got two ticks within the resolution.

  2.          if( g_min_dttick_ms==0 ) while(1);

    Why do you have this infinite loop in your code?

 
William Roeder:
  1. You got two ticks within the resolution.

  2. Why do you have this infinite loop in your code?

Hi William and thanks for your answer,

1. Ok now I better understand: it's possible to have two ticks in one go.

2. yes, for debug.


Thanks a lot!

Reason: