Time[] in MT4 but no in MT5

 

Dear Coder,

I need your help to explain me how to use the function of Time[] in MT5 which is exit in MT4 but not in MT5. How can I fix it in MT5?

 
intrania13:

Dear Coder,

I need your help to explain me how to use the function of Time[] in MT5 which is exit in MT4 but not in MT5. How can I fix it in MT5?

In the indicator or in the adviser?
 
intrania13:

Dear Coder,

I need your help to explain me how to use the function of Time[] in MT5 which is exit in MT4 but not in MT5. How can I fix it in MT5?

Use CopyTime. Here is an article with details about migrating from MQL4 to MQL5.
 
Stanislav Korotky:
Use CopyTime. Here is an article with details about migrating from MQL4 to MQL5.

"In MQL5 chart period constants changed, and some new time periods (M2, M3, M4, M6, M10, M12, H2, H3, H6, H8, H12) were added."

Thanks this article really helps

 

check this one too

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

Transferring Indicators from MQL4 to MQL5
Transferring Indicators from MQL4 to MQL5
  • 2010.07.28
  • Vasily
  • www.mql5.com
This article is dedicated to peculiarities of transferring price constructions written in MQL4 to MQL5. To make the process of transferring indicator calculations from MQL4 to MQL5 easier, the mql4_2_mql5.mqh library of functions is suggested. Its usage is described on the basis of transferring of the MACD, Stochastic and RSI indicators.
 
Why the didnt put Time[] TimeDayOfTheWeek()  That were pretty good functions!!!
 

I mean seriously... compare this code to express the same idea.. and are you still wondering why MQL5 has been a failure? Why change it to copy time or not make some compatibility so we dont have to rewrite all indicators? Omg...


MQL4:

Alert(Time[0]);

MQL5:

//--- variables for function parameters
int start = 0; // bar index
int count = 1; // number of bars
datetime tm[]; // array storing the returned bar time
//--- copy time 
CopyTime(_Symbol,PERIOD_D1,start,count,tm);
//--- output result
Alert(tm[0])
 
I agree.
 
Marco vd Heijden:
I agree.

Why not, simply use:

iTime(_Symbol,_Period,0);
???
 
Dadas:

Why not, simply use:

???

These were added somewhat later.

 
#define DEFINE_TIMESERIE(NAME, T)                \
  class CLASS##NAME                              \
  {                                              \
  public:                                        \
    T operator[]( const int iPos ) const         \
    {                                            \
      return(::i##NAME(_Symbol, _Period, iPos)); \
    }                                            \
  };                                             \
                                                 \
  CLASS##NAME NAME;

  DEFINE_TIMESERIE(Volume, long)
  DEFINE_TIMESERIE(Time, datetime)
  DEFINE_TIMESERIE(Open, double)
  DEFINE_TIMESERIE(High, double)
  DEFINE_TIMESERIE(Low, double)
  DEFINE_TIMESERIE(Close, double)
#undef DEFINE_TIMESERIE


Reason: