Emulating Time[] of MQL4 does not work

To add comments, please log in or register
Ziad El
122
Ziad El  

I am trying to write a function that emulates Time[] of MQL4 in MQL5:

datetime Time(string Pair, ENUM_TIMEFRAMES Tim, int N)
{
int start = 0; // bar index
int count = N; // number of bars
datetime tm[]; // array storing the returned bar time
ArraySetAsSeries(tm,true);
CopyTime(Pair,Tim,start,count,tm); //--- copy time 
int i = ArraySize(tm);                 
Alert (i);                         // THIS GIVES ME 0!
return tm[N];  //--- output result. THIS GIVES ME ARRAY OUT OF RANGE!
} 

Can you help please?

Marco vd Heijden
Moderator
8370
Marco vd Heijden  

Hello you can use 

iTime(_Symbol,PERIOD_CURRENT,0);
whroeder1
17927
whroeder1  
No need to write your own, MT5 has iTime, iOpen, iHigh, iLow, iClose, iVolume, iBars, iBarShift, iLowest, iHighest, iRealVolume, iTickVolume, iSpread
          New MetaTrader 5 Platform beta build 1845: MQL5 functions for operations with bars and Strategy Tester improvements - Options Trading Strategies - General - MQL5 programming forum 2018.06.08 13:02
Marco vd Heijden
Moderator
8370
Marco vd Heijden  

Yeah why don't you add some more then ?

//+------------------------------------------------------------------+
int TimeHour(datetime time)
  {
   MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.hour);
  }
//+------------------------------------------------------------------+
There is still need to write your own and it's a lot actually.
To add comments, please log in or register