Drop down list for timeframe
It works, you just have to double click the field to show the drop-down. I'm assuming you rolled your own timeframe enum to filter the choices down to just the ones you want to show. If you don't want to filter then you can just use the standard MQL ENUM_TIMEFRAMES. Otherwise, you'll want to convert your filtered enum back to ENUM_TIMEFRAMES after user selection.
enum MY_TIMEFRAME { M1, // One minute M5, // Five minute M15, // Fifteen minute M30, // Thirty minute H1, // One hour H4, // Four hour CURRENT // Use current timeframe, or double-click to change }; input MY_TIMEFRAME inp_timeframe = CURRENT; //Select the chart timeframe ENUM_TIMEFRAMES myTimeFrameToMqlTimeFrame(MY_TIMEFRAME tf) { switch(tf) { case M1: return PERIOD_M1; case M5: return PERIOD_M5; case M15: return PERIOD_M15; case M30: return PERIOD_M30; case H1: return PERIOD_H1; case H4: return PERIOD_H4; } return PERIOD_CURRENT; } ENUM_TIMEFRAMES g_timeframe = NULL; int OnInit() { g_timeframe = myTimeFrameToMqlTimeFrame(inp_timeframe); ChartSetSymbolPeriod(0, NULL, g_timeframe); return INIT_SUCCEEDED; }
enum MY_TIMEFRAME { M1 =PERIOD_M1, // One minute M5 =PERIOD_M5, // Five minute M15 =PERIOD_M15, // Fifteen minute M30 =PERIOD_M30, // Thirty minute H1 =PERIOD_H1, // One hour H4 =PERIOD_H4, // Four hour CURRENT =PERIOD_CURRENT // Use current timeframe, or double-click to change }; input MY_TIMEFRAME inp_timeframe = CURRENT; //Select the chart timeframe /* * ENUM_TIMEFRAMES myTimeFrameToMqlTimeFrame(MY_TIMEFRAME tf) { * switch(tf) { * case M1: return PERIOD_M1; * case M5: return PERIOD_M5; * case M15: return PERIOD_M15; * case M30: return PERIOD_M30; * case H1: return PERIOD_H1; * case H4: return PERIOD_H4; * } * return PERIOD_CURRENT; * * } * * ENUM_TIMEFRAMES g_timeframe = NULL; */ int OnInit() { // g_timeframe = myTimeFrameToMqlTimeFrame(inp_timeframe); ChartSetSymbolPeriod(0, NULL, (ENUM_TIMEFRAMES) inp_timeframe); return INIT_SUCCEEDED; }
I agree. I would just simplify thus
Is there a way to do this for a dropdown choice of indicators please ? e.g. C1="Vortex", C2="SSL", etc, etc ? If I replace '=PERIOD_M1' with "Vortex" I get the message - "constant expression is not integral "
Thanks
-
You can use EnumToString if it is an exact match.
Need some help with some MT5 code - MT5 - Expert Advisors and Automated Trading - MQL5 programming forum #3 (2018) -
Or, do the conversion yourself.
enum Indicator { Vortex, SSL, … }; const string indicatorString[]={ "Vortex", "SSL123" …]; input Indicator inp_indicator = Vortex; //Select the chart indicator int OnInit(){ string indicator = indicatorString[inp_indicator]; ⋮
-
You can use EnumToString if it is an exact match.
Need some help with some MT5 code - MT5 - Expert Advisors and Automated Trading - MQL5 programming forum #3 (2018) -
Or, do the conversion yourself.

- 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 all,
The MT4 code below presents allows me to set the time frame for the current chart by way of a drop down list. Unfortunately, it doesn't work with MT5.
Would somebody please point me in the right direction.
regards ....