TimeCurrent - 20 days

 

Hi all

Question :

How i can go 20 days back from TimeCurrent() ?

Or 1 month from TimeCurrent.

It's interesting to use CopyRates() with time - X days

Thanks for help

   MajorDad

Documentation on MQL5: Timeseries and Indicators Access / CopyRates
  • www.mql5.com
Timeseries and Indicators Access / CopyRates - Documentation on MQL5
 
MajorDad:

Hi all

Question :

How i can go 20 days back from TimeCurrent() ?

Or 1 month from TimeCurrent.

It's interesting to use CopyRates() with time - X days

Thanks for help

   MajorDad

It's to easy, that pro's can answere this simple question O_o

But for all, interesting this question, here the answere from not a pro ^__~

   int HDays = 14;    //we want 14 days back from TimeCurrent()
   MqlDateTime time1, time2;
   TimeToStruct( TimeCurrent() - (HDays * 24) *60 *60 , time1 );
   TimeToStruct( TimeCurrent() , time2 );
   datetime tim1 = StructToTime( time1 );
   datetime tim2 = StructToTime( time2 );
   txt = txt + " tim1 = " + tim1 + "  tim2 = " + tim2 + "\n";
   int hCopied = CopyRates( Symbol(), Period(), tim1, tim2, Hrates );
   if (hCopied >0 ){
      txt = txt + " Copied Bars = " + hCopied + "\n";
      txt = txt + " datetime1 = " + Hrates[0].time + "\n";
      txt = txt + " datetime2 = " + Hrates[hCopied-1].time + "\n";
      for ( i = 0; i <= hCopied; i++ ){
         //your code here
      }
   }