Define timeframe as input in mql5 and initializing it

 

Hi. 

enum timeframe
  {
   M30 = PERIOD_M30,
   H1 = PERIOD_H1,
   H4 = PERIOD_H4,
   D1 = PERIOD_D1,
   W1 = PERIOD_W1,
   MN1 = PERIOD_MN1,
  };

input timeframe = PERIOD_H4;


int OnInit(){
   macdHandle = iMACD(_Symbol, PERIOD_H4, 12, 26, 9, PRICE_CLOSE);
}


I just migrate from mql4 to mql5 and I can't define timeframe as input and initializing it. 

Can anyone help me to do that?

Thank you so much.

 
input timeframe InpTF = H4;
 
Soheil Hossein:

Hi. 


I just migrate from mql4 to mql5 and I can't define timeframe as input and initializing it. 

Can anyone help me to do that?

Thank you so much.

No need to create a new enumeration.

The solution is the same in MQL4 and MQL5

input ENUM_TIMEFRAMES   timeframe = PERIOD_H4;  // Timeframe for MACD

int OnInit()
{
   macdHandle = iMACD(_Symbol, timeframe, 12, 26, 9, PRICE_CLOSE);
}
 
  1. Fernando Morales: No need to create a new enumeration.

    Unless you want to restrict the valid timeframes to just those listed.

  2. Why did you post your MT5 question in the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  3.    macdHandle = iMACD(_Symbol, PERIOD_H4, 12, 26, 9, PRICE_CLOSE);
    If you want to pass timeframe to the MACD, cast it to a ENUM_TIMEFRAMES. That is why your original enumeration used PERIOD_… as values.
Reason: