Why Not work CopyTicksRange?

 
int OnInit()
  {


    MqlTick  tick_Range[] , tick[] ;
    int copied_Range , copied ;
    
    datetime Start = D'2016.11.11';
    datetime End   = D'2016.12.12';
    
    
    copied_Range = CopyTicksRange( Symbol() , tick_Range , COPY_TICKS_TRADE , Start , End  );
    copied       = CopyTicks     ( Symbol() , tick       , COPY_TICKS_TRADE , 0     , 1000 );



    Print( "copied_Range = " , copied_Range , "   |   " , "copied = " , copied );


//---
   return(0);
  }

This is Print result :

copied_Range = 0   |   copied = 1000

 
Please read the documentation. The dates should be provided as ulong in milliseconds, not datetime.
 
Alain Verleyen:
Please read the documentation. The dates should be provided as ulong in milliseconds, not datetime.

Hi

I've read this before

I casted datetime to millisecond but not work

int OnInit()
  {


    MqlTick  tick_Range[] , tick[] ;
    int copied_Range , copied ;
    
    datetime Start_date = D'2016.11.11';
    datetime End_date   = D'2016.12.12';
    
    ulong Start = ulong(Start_date);
    ulong End   = ulong(End_date  );
    
    copied_Range = CopyTicksRange( Symbol() , tick_Range , COPY_TICKS_TRADE , Start , End  );
    copied       = CopyTicks     ( Symbol() , tick       , COPY_TICKS_TRADE , 0     , 1000 );


    Print( "Start = "        , Start        , "   |   " , "End = "    , End    );
    Print( "copied_Range = " , copied_Range , "   |   " , "copied = " , copied );


//---
   return(0);
  }

Print result :

Start = 1478822400   |   End = 1481500800

copied_Range = 0   |   copied = 1000

 

My casting is wrong?

 

Type casting alone isn't going to fix it.

datetime is the number of seconds elapsed since 01 January 1970.

What you have done is stored the number of seconds elapsed since 01 January 1970 into a ulong variable.

You need to convert the value to milliseconds (1000 times more...)

 
honest_knave:

Type casting alone isn't going to fix it.

datetime is the number of seconds elapsed since 01 January 1970.

What you have done is stored the number of seconds elapsed since 01 January 1970 into a ulong variable.

You need to convert the value to milliseconds (1000 times more...)

oh . you are right

I was confused

I change to this

ulong Start = ulong(Start_date)*1000;
ulong End   = ulong(End_date  )*1000;
thank you
 
Ehsan Tavakoli:
oh . you are right

I was confused

I change to this

ulong Start = ulong(Start_date)*1000;
ulong End   = ulong(End_date  )*1000;
thank you

I need to use CopyTicksRange and CopyTicks  they both do not work. I am constructing a array of lasts. Very simple. But would like to verify with one of these two, but both are not working for me. They keep returning -1. Here is the simple code I thought about:


int qteTick=0;
double ArrayDeLast[];

void OnTick()
  {
  double Last=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_LAST),_Digits);
  ArrayResize(ArrayDeLast,qteTick+1);
  ArrayDeLast[qteTick]=Last;
  qteTick=qteTick+1;
}

The code above works fine. No problem. But the code below does not. I have tried use OnInit function replacing the OnTick. Also have tried using the "End" and "Start" variables. No success. Is there a declartion needed for copyTicks to work?

void OnTick()
  {
  MqlTick ArrayDeTicks[];
  MqlTick tick[];
  int copied_Range , copied ; 
    

//    ulong End   = ulong(TimeCurrent());
//    ulong Start = End-10;
  
  copied_Range = CopyTicksRange( Symbol() , ArrayDeTicks , COPY_TICKS_TRADE , 1585217010000 , 1585217011000  ); 
  copied       = CopyTicks     ( Symbol() , tick       , COPY_TICKS_TRADE , 0     , 1000 ); 
  Comment(copied_Range," ",copied);  

  }

Regards,

 
douglas14:

I need to use CopyTicksRange and CopyTicks  they both do not work. I am constructing a array of lasts. Very simple. But would like to verify with one of these two, but both are not working for me. They keep returning -1. Here is the simple code I thought about:


The code above works fine. No problem. But the code below does not. I have tried use OnInit function replacing the OnTick. Also have tried using the "End" and "Start" variables. No success. Is there a declartion needed for copyTicks to work?

Regards,

Your functions seem to be fine, try with COPY_TICKS_ALL, if it does not work, You can verify if your broker provides ticks, look into the definitions of the instrument you are trading, if they are not available, try to change your instrument or your broker. Also, when using ArrayResize that way. It is better to use the third argument, reserve size. that way, ArrayResize will execute only when needed, that is, when exceeding the reserve size, improving your overall code speed.
Reason: