Download MetaTrader 5

Why are MT5 ENUM_TIMEFRAMES fubar?

To add comments, please log in or register
Format text in the messages editor. It is convenient!
data46
27
data46 2015.06.12 04:46 

In MT5, using Print(PERIOD_M1,PERIOD_M5, etc...), we get:

  • M1    1
  • M5    5
  • M15  15
  • M30  30
  • H1    16385
  • H4    16388
  • D1    16408
  • W1   32769
  • MN1  49153

In MT4, the ENUM constants were conveniently the minutes, but why have they chosen obscure constants for higher timeframes?

Chart Timeframes - MQL4 Documentation
  • docs.mql4.com
Chart Timeframes - MQL4 Documentation
Jian Chen
Moderator
3620
Jian Chen 2015.06.12 05:50  

I agree with you, the definition of these values in MT5 is a little strange.

I think it depends on the design. Let me decode these values:

1. minutes time frames:

   M1 = 0<<15+1, M5 = 0<<15+5, M15 = 0<<15+15, M30=0<<15+30

2. hours and days time frames:

   H1 = 1<<15+1, H4 = 1<<15+4, D1 = 1<<15+24

3. week time frame:

   W1 = 2<<15+1

4. month time frame:

   MN1 = 3<<15+1 

Alain Verleyen
Moderator
30743
Alain Verleyen 2015.06.12 11:25  
data46:

In MT5, using Print(PERIOD_M1,PERIOD_M5, etc...), we get:

  • M1    1
  • M5    5
  • M15  15
  • M30  30
  • H1    16385
  • H4    16388
  • D1    16408
  • W1   32769
  • MN1  49153

In MT4, the ENUM constants were conveniently the minutes, but why have they chosen obscure constants for higher timeframes?

There is no point to use the numeric values. What to do ?
data46
27
data46 2015.06.12 19:23  
Alain Verleyen:
There is no point to use the numeric values. What to do ?

Perhaps there is; what if I wanted to check timestamps:

if (tick.time != (rates[0].time + PERIOD_M5)) processNewCandle(); 

To state there's 'no point' seems like you're not embracing coding creativity.

I say this because using CopyRates or any derivative of that function such as CopyClose, CopyTime, etc absolutely hammers CPU. The fastest way to access data is using the MqlTick structure.

I presume CopyRates does a lot of processing in the background, such as checking raw files if the data exists and then polling the server to retrieve missing data. Caching tick data seems a way around this bottleneck, but there's not enough info in the MqlTick structure, as it's a pure sequential stream of data that has no concept of open, closes et al.

Hence my question was to somehow compare timestamps using MqlTick.

data46
27
data46 2015.06.12 19:29  
Jian Chen:

I agree with you, the definition of these values in MT5 is a little strange.

I think it depends on the design. Let me decode these values:

1. minutes time frames:

   M1 = 0<<15+1, M5 = 0<<15+5, M15 = 0<<15+15, M30=0<<15+30

2. hours and days time frames:

   H1 = 1<<15+1, H4 = 1<<15+4, D1 = 1<<15+24

3. week time frame:

   W1 = 2<<15+1

4. month time frame:

   MN1 = 3<<15+1 

Thanks for your reply Jian.

Is that a bitwise operation? I'm a simpleton and using numeric constants would be far more intuitive.

Alain Verleyen
Moderator
30743
Alain Verleyen 2015.06.12 23:02  
data46:

Perhaps there is; what if I wanted to check timestamps:

To state there's 'no point' seems like you're not embracing coding creativity.

There is no point to use the numeric values. Your code doesn't make sense even with MT4.

You probably need PeriodSeconds() function.

data46
27
data46 2015.06.13 00:31  
Alain Verleyen:

There is no point to use the numeric values. Your code doesn't make sense even with MT4.

You probably need PeriodSeconds() function.

My snippet was psuedo-code; thanks for the PeriodSeconds() function, I'll see if it fulfils my needs.
JD4
1101
JD4 2015.06.24 04:02  
data46:

Perhaps there is; what if I wanted to check timestamps:

To state there's 'no point' seems like you're not embracing coding creativity.

I say this because using CopyRates or any derivative of that function such as CopyClose, CopyTime, etc absolutely hammers CPU. The fastest way to access data is using the MqlTick structure.

I presume CopyRates does a lot of processing in the background, such as checking raw files if the data exists and then polling the server to retrieve missing data. Caching tick data seems a way around this bottleneck, but there's not enough info in the MqlTick structure, as it's a pure sequential stream of data that has no concept of open, closes et al.

Hence my question was to somehow compare timestamps using MqlTick.

What makes more coding sense?  Using the constant name in your coding, or trying to use the values themselves?  I do not call doing that "coding creativity", I call that making the job harder than it has to be.  In programming (at least the courses I have taken) you use the constant name specifically because it is just that, a constant.  If you need to calculate values from that, it is easier to use the constant name in your equations.  I agree that the constant values need to be correct for what they are trying to figure out, but that is how MQL is working currently, apparently.
To add comments, please log in or register