Download MetaTrader 5
To add comments, please log in or register
Manage agents in your profile. It is easy!
marcovth
55
marcovth 2013.07.31 22:44 

Hello ...

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

Thanks.  

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.07.31 23:08  
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.
marcovth
55
marcovth 2013.07.31 23:15  

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.
/
To add comments, please log in or register