CopyTicks Problem

 
MqlTick Tab [] ;
ulong d = (ulong)(D'2019.12.17 10:00:00') ;

void OnStart(){

   CopyTicks(_Symbol,Tab,COPY_TICKS_ALL,d,1) 
   Print(Tab[0].time  );
  
}

I'm trying to get a tick but when i check it by printing tick's date i get  2011.12.19 00:00:08 and if i replace COPY_TICKS_ALL by COPY_TICKS_TRADE i get 2017.02.02 16:30:53
The same problem for any date
 

*

datetime from=D'2019.12.17 10:00:00';
ulong d = (ulong)from*1000;
 

Script:

//+------------------------------------------------------------------+
//|                                                      Test_en.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.002"
#property script_show_inputs
//+------------------------------------------------------------------+
//| Enum Flags Copy Ticks                                            |
//+------------------------------------------------------------------+
enum ENUM_FLAGS_COPY_TICKS
  {
   info  = 0,  // COPY_TICKS_INFO
   trade = 1,  // COPY_TICKS_TRADE
   all   = 2,  // COPY_TICKS_ALL
  };
//--- input
input ENUM_FLAGS_COPY_TICKS InpTicks   = info;  // The type of received ticks
input datetime InpFrom                 = 0;     // The date from which you want to request ticks
input int      InpGetTicks             = 1;     // The number of required ticks
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int      attempts=0;       // Count of attempts
   bool     success=false;    // The flag of a successful copying of ticks
   MqlTick  tick_array[];     // Tick receiving array
//---
   uint     flags=0;
   string   string_flags="-";
   switch(InpTicks)
     {
      case  info:
         flags=COPY_TICKS_INFO;
         string_flags="COPY_TICKS_INFO";
         break;
      case trade:
         flags=COPY_TICKS_TRADE;
         string_flags="COPY_TICKS_TRADE";
         break;
      default:
         flags=COPY_TICKS_ALL;
         string_flags="COPY_TICKS_ALL";
         break;
     }
//---
   Print("---");
   Print(string_flags," from: ",TimeToString(InpFrom,TIME_DATE|TIME_SECONDS)," ",IntegerToString(InpGetTicks)," ticks");
//--- make 3 attempts to receive ticks
   while(attempts<3)
     {
      //--- Measuring start time before receiving the ticks
      uint start=GetTickCount();
      //--- Requesting the tick history
      int received=CopyTicks(Symbol(),tick_array,flags,(ulong)InpFrom*1000,InpGetTicks);
      if(received!=-1)
        {
         //--- Showing information about the number of ticks and spent time
         PrintFormat("%s: received %d ticks in %d ms",Symbol(),received,GetTickCount()-start);
         //--- If the tick history is synchronized, the error code is equal to zero
         if(GetLastError()==0)
           {
            success=true;
            break;
           }
         else
            PrintFormat("%s: Ticks are not synchronized yet, %d ticks received for %d ms. Error=%d",
                        Symbol(),received,GetTickCount()-start,_LastError);
        }
      //--- Counting attempts
      attempts++;
      //--- A one-second pause to wait for the end of synchronization of the tick database
      Sleep(1000);
     }
//--- Receiving the requested ticks from the beginning of the tick history failed in three attempts
   if(!success)
     {
      PrintFormat("Error! Failed to receive %d ticks of %s in three attempts",InpGetTicks,Symbol());
      return;
     }
   int ticks=ArraySize(tick_array);
   if(ticks<1)
     {
      PrintFormat("Error! ArraySize %d ",ticks);
      return;
     }
//--- Showing the time of the first tick in the array
   datetime firstticktime=tick_array[ticks-1].time;
   PrintFormat("Last tick time = %s.%03I64u",
               TimeToString(firstticktime,TIME_DATE|TIME_MINUTES|TIME_SECONDS),tick_array[ticks-1].time_msc%1000);
//--- Show the time of the last tick in the array
   datetime lastticktime=tick_array[0].time;
   PrintFormat("First tick time = %s.%03I64u",
               TimeToString(lastticktime,TIME_DATE|TIME_MINUTES|TIME_SECONDS),tick_array[0].time_msc%1000);
  }
//+------------------------------------------------------------------+
Files:
Test_en.mq5  9 kb
 
Vladimir Karputov:

*

Thanks Vladimir 

It works but i have two more questions please  ,  why we multiply the date by 1000 and why i can't receive ticks before 2011.12.19

 
anazaml:

why we multiply the date by 1000

datetime -> milliseconds 


anazaml:

why i can't receive ticks before 2011.12.19 

I twisted the crystal ball and it says: read the messages in the "Experts" tab

 
Vladimir Karputov:

datetime -> milliseconds 


I twisted the crystal ball and it says: read the messages in the "Experts" tab

Please i searched in the "Experts" tab about my second question and i couldn't get answers , can you just answer me please or gvive me a link

Thanks again

 
anazaml :

Please i searched in the "Experts" tab about my second question and i couldn't get answers , can you just answer me please or gvive me a link

Thanks again

I can’t read minds. I am not a telepath.

 
anazaml:

Please do not open a new topic with the same questions that you have in this topic.

I have deleted your other topic.

 
Tick history data is provided by your broker. It's not unusual that you don't get more than a few years.