input timeframe InpTF = H4;
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); }
- Fernando Morales: No need to create a new enumeration.
Unless you want to restrict the valid timeframes to just those listed.
-
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. -
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.
If you want to make an input of only your custom timeframes to just those listed.
You can use something like using a switch statement in OnInit Function.
ENUM_TIMEFRAMES TimeFrame = PERIOD_M5; enum MY_TIMEFRAME { Period_M1, // 1 Minute (Default) Period_M5, // 5 Minute Period_M15, // 15 Minute Period_M30, // 30 Minute Period_H1, // 1 Hour Period_H4 // 4 Hour }; input MY_TIMEFRAME InpTimeFrame = Period_M1; int OnInit() { switch(InpTimeFrame) { case Period_M1: TimeFrame=PERIOD_M1; break; case Period_M5: TimeFrame=PERIOD_M5; break; case Period_M15: TimeFrame=PERIOD_M15; break; case Period_M30: TimeFrame=PERIOD_M30; break; case Period_H1: TimeFrame=PERIOD_H1; break; default: TimeFrame=PERIOD_CURRENT; break; } return(INIT_SUCCEEDED); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.