How to find bar index for ertain datetime?

 

Hello ...

 Is there a function that finds the (closest) bar-index for a certain given datetime?

Thanks.  

 
marcovth:

Hello ...

 Is there a function that finds the (closest) bar-index for a certain given datetime?

Thanks.  

iBarShift() in mql4 but I don't believe there is an equivalent in mql5, use the search and have a look.
 

Thanks ...

 https://www.mql5.com/en/articles/81

int iBarShiftMQL4(string symbol,
                  int tf,
                  datetime time,
                  bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
     {
      if(ArraySize(Arr)>2) return(ArraySize(Arr)-1);
      if(time<time1) return(1);
      else return(0);
     }
   else return(-1);
  }
Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • 2010.05.17
  • Sergey Pavlov
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
Reason: