How can I set the default value of an integer input parameter based on chart timeframe? For example if loaded in 1min, the default value becomes 123 and for 5min chart it becomes 456.
Nabeel Bashir:
How can I set the default value of an integer input parameter based on chart timeframe? For example if loaded in 1min, the default value becomes 123 and for 5min chart it becomes 456.
Use ENUM_TIMEFRAMES and if else. Or Chart period() function
How can I set the default value of an integer input parameter based on chart timeframe? For example if loaded in 1min, the default value becomes 123 and for 5min chart it becomes 456.
Nabeel Bashir:
How can I set the default value of an integer input parameter based on chart timeframe? For example if loaded in 1min, the default value becomes 123 and for 5min chart it becomes 456.
How can I set the default value of an integer input parameter based on chart timeframe? For example if loaded in 1min, the default value becomes 123 and for 5min chart it becomes 456.
You can't set input variables dynamically — they are fixed at compile time. But you can use a variable instead and assign its value in OnInit() based on the current chart timeframe.
Example:
```mql5 input int Param = 0; // Just placeholder, not used int actualParam; int OnInit() { switch(Period()) { case PERIOD_M1: actualParam = 123; break; case PERIOD_M5: actualParam = 456; break; default: actualParam = 999; break; } Print("Using param: ", actualParam); return INIT_SUCCEEDED; } ``` This way you get dynamic behavior while keeping one visible `input` if needed.
This way you get dynamic behavior while keeping one visible input if needed.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register