CopyTicks unexpected results

 

Hello

Why does CopyTicks return ticks that are older than the [in] date parameter? From the documentation:

[in]   The date from which you want to request ticks. In milliseconds since 1970.01.01. If from=0, the last count ticks will be returned.

I have a tick helper class that calls my CopyTicks function. I call this function multiple times until the required ticks have been read. Each successive call will pass the date parameter with the millisecond time +  1 of the last tick of the previous call. In this way I can process a lot of ticks (eg. 300 million or more) without overloading memory.

Mql CopyTicks behaves as expected until [in] + count exceeds the end of price history, ie new ticks not yet received. So, if I call Mql CopyTicks with [in] set to the millisecond time of the last tick in the price history, this function will return several thousand ticks BEFORE [in].

Rob

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int cTickHelper::CopyTicks(string symbol, MqlTick &tickData[], ulong date, int count)
{
   int result = 0;

   for (int try = 0; try < TICKHELPER_COPYTICKS_MAXTRIES; try++)
   {
      result = CopyTicks(symbol, tickData, COPY_TICKS_INFO, date, (uint)count);

      if (result == -1)
      {
         PrintFormat("%s: %d", __FUNCTION__, GetLastError());
      }
      else
      {
         if (result != 0 && tickData[result - 1].time_msc < (long)date)
         {
            //
            // should never get here, but it does. Why??
            //

            ArrayFree(tickData);
            
            result = 0;
         }
         
         return result;
      }

      Wait(TICKHELPER_COPYTICKS_SLEEPTIMEINMS);
   }

   return result;
}
 
robnorthen:

Hello

Why does CopyTicks return ticks that are older than the [in] date parameter? From the documentation:

[in]   The date from which you want to request ticks. In milliseconds since 1970.01.01. If from=0, the last count ticks will be returned.

I have a tick helper class that calls my CopyTicks function. I call this function multiple times until the required ticks have been read. Each successive call will pass the date parameter with the millisecond time +  1 of the last tick of the previous call. In this way I can process a lot of ticks (eg. 300 million or more) without overloading memory.

Mql CopyTicks behaves as expected until [in] + count exceeds the end of price history, ie new ticks not yet received. So, if I call Mql CopyTicks with [in] set to the millisecond time of the last tick in the price history, this function will return several thousand ticks BEFORE [in].

Rob

If I understand well you are calling this function to get inexistent ticks ? Seems like a bug, but it also seems easy to avoid.

What are the date/count values when it happens ?

 

Hi Alain

[in] = 1622242799967, count = 20000000, symbol = #Germany30

Returns 87,076 ticks between 1622172662124 and 1622242799966.

Yes, it is easy to avoid, but it's still a bug and should be fixed.

Thanks,

Rob

Reason: