Time[] Function in MQL5

 

Hello people, I'm trying to create Time[] for my MT5 indicator but there's something wrong and I don't know what :/ 

So, this is a Class code in *mqh 

#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

Which should work in indicator as Time[] function, but it gives me an error: 

 'operator[]' - cannot convert enum'

I found this *mqh Class here but is seems it's not working properly, can you guys help me fix this? I guess it might even be useful for others too.
Thanks in advance.

 
You can use 
datetime time = iTime(Symbol(),PERIOD_CURRENT,shift);
As well as the others for Open High Low Close Volume see: https://www.mql5.com/en/docs/series
Documentation on MQL5: Timeseries and Indicators Access
Documentation on MQL5: Timeseries and Indicators Access
  • www.mql5.com
These are functions for working with timeseries and indicators. A timeseries differs from the usual data array by its reverse ordering - elements of timeseries are indexed from the end of an array to its begin (from the most recent data to the oldest ones). To copy the time-series values and indicator data, it's recommended to use dynamic...
 
Marco vd Heijden:
You can use  As well as the others for Open High Low Close Volume see: https://www.mql5.com/en/docs/series

I need array, Time[0], iTime(0) is different

 

This is my code:

iTime(gsa_916[ai_0], gia_892[ai_0], ai_4);

and gia_892[qi_0] is Time[] that's why I need time array

 

It will both return the same value.

That seems to be decompiled code.

 
Marco vd Heijden:

It will both return the same value.

That seems to be decompiled code.

Yes, I'm trying to make my MT4 indicator usable for MT5 :) but it really seem HARD :/ I'll take brake and I'll try later :) I need to rest :)

 
Actually you know what?
iTime(Symbol(),_Period,0)

this returns different values in MT5 :/

MT4: 1586863800
MT5: 2020.04.14 11:30:00

in MT4 iTime() and Time[] gives me same result, but you see it's different result in MT5  :/

 

Because you use shift zero so that's going to be a different bar.

You can have time in (milli)seconds from epoch or a date with a year month day hour minute second etc.

The last parameter is the index value it's the same as what you would normally put between[0]

This

iTime(Symbol(),_Period,0)

Is the same as this

Time[0];

It would probably be a lot easier for you if you used written source code in stead of decompiled code.


 
Marco vd Heijden:

Because you use shift zero so that's going to be a different bar.

You can have time in (milli)seconds from epoch or a date with a year month day hour minute second etc.

The last parameter is the index value it's the same as what you would normally put between[0]

This

Is the same as this

It would probably be a lot easier for you if you used written source code in stead of decompiled code.


Seems like I've got much more problem than Time[] :)
:/

but, thanks anyway 

 
mr-roma:

Which should work in indicator as Time[] function, but it gives me an error

void OnStart()
{
  Print(Time[0]);
}
'Test6.mq5'     Test6.mq5       1       1
code generated          1       1
0 errors, 0 warnings, 209 msec elapsed          1       1
 
fxsaber:

Which version are you using?

Reason: