How can I multiply ENUM_TIMEFRAMES?

 

Hello,

I made this test script and it doesn't work because I don't know how to multily timeframes correctly.

void OnStart() {
   ENUM_TIMEFRAMES tf=PERIOD_M5;
   ENUM_TIMEFRAMES htf=tf*48;
   Print(htf);
   ChartOpen(_Symbol,htf);
}

Print works fine, the result is 240 but the opened chart is always PERIOD_H1.

There is always a warning from the compiler: implicit enum conversion.

How can I correct that?

 
Marbo:

Hello,

I made this test script and it doesn't work because I don't know how to multily timeframes correctly.

Print works fine, the result is 240 but the opened chart is always PERIOD_H1.

There is always a warning from the compiler: implicit enum conversion.

How can I correct that?

I just found something to avoid the implicit enum conversion but the opened chart is still the PERIOD_H1 timeframe:

void OnStart() {
   ENUM_TIMEFRAMES tf=PERIOD_M5;
   ENUM_TIMEFRAMES htf=(ENUM_TIMEFRAMES)(tf*48);
   Print(htf);
   ChartOpen(_Symbol,htf);
}
 
Marbo #:

I just found something to avoid the implicit enum conversion but the opened chart is still the PERIOD_H1 timeframe:

I also tried this but without any success:

ChartOpen(_Symbol,(ENUM_TIMEFRAMES)(PERIOD_M5*48));

 

You can't multiply ENUM_TIMEFRAMES.

You have to convert them into seconds (the "time currency" of MQ) to use them in a calculation.

 

PERIOD_H1 to PERIOD_D1 are internally represented as 16384+number_of_hours. (don't ask me why :)). You can find out more by means of a simple:

void OnStart()
  {
  Print(Period());  
  }

Then there is PeriodSeconds() to convert ENUM_TIMEFRAMES into numbers you can use in calculations; but you'll have to write your own function to convert them back.

Documentation on MQL5: Common Functions / PeriodSeconds
Documentation on MQL5: Common Functions / PeriodSeconds
  • www.mql5.com
PeriodSeconds - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Haruto Rat #:

PERIOD_H1 to PERIOD_D1 are internally represented as 16384+number_of_hours. (don't ask me why :)). You can find out more by means of a simple:

Then there is PeriodSeconds() to convert ENUM_TIMEFRAMES into numbers you can use in calculations; but you'll have to write your own function to convert them back.

Thanks guys! Now I know how to go on.