limit the periods in ENUM_TIMEFRAMES as input

To add comments, please log in or register
Essam Daoud
1132
Essam Daoud  

Hi

Is there a way to limit the periods available in the ea input for the ENUM_TIMEFRAMES like to only show and PERIOD_H1?

I tried few ways but could not get it to work.

Thanks

Seng Joo Thio
1676
Seng Joo Thio  
samjesse:

Hi

Is there a way to limit the periods available in the ea input for the ENUM_TIMEFRAMES like to only show and PERIOD_H1?

I tried few ways but could not get it to work.

Thanks

You can refer to https://www.mql5.com/en/docs/basis/variables/inputvariables, specifically, under the header:

Enumerations as input Parameters

Documentation on MQL5: Language Basics / Variables / Input Variables
Documentation on MQL5: Language Basics / Variables / Input Variables
  • www.mql5.com
modifier is indicated before the data type. A variable with the input modifier can't be changed inside mql5-programs, such variables can be accessed for reading only. Values of input variables can be changed only by a user from the program properties window. External variables are always reinitialized immediately before the OnInit() is called...
Keith Watford
Moderator
21780
Keith Watford  

Something like

enum tf  
   { 
    H1=60,    
    H4=240, 
   };
Alain Verleyen
39533
Alain Verleyen  
Keith Watford:

Something like

enum tf  
   { 
    H1=PERIOD_H1,    
    H4=PERIOD_H4
   };
Don't hardcode period values.
Marcin Rutkowski
302
Marcin Rutkowski  
samjesse:

Hi

Is there a way to limit the periods available in the ea input for the ENUM_TIMEFRAMES like to only show and PERIOD_H1?

I tried few ways but could not get it to work.

Thanks

Enums are based on integers, so you can just create new

1 . enum like sugested above

2. # define

3 .just use integer variable

4 .do mix of define and enum   - my advice is to use #define  ...this is very very  very very very  very very very very very usfull. I recomend to invest time to lern everything about it :)

Essam Daoud
1132
Essam Daoud  
Alain Verleyen:
Don't hardcode period values.

And how would you convert from tf to ENUM_TIMEFRAMES? as I am getting an error when the tf in used in some function parameters expecting ENUM_TIMEFRAMES.

William Roeder
20695
William Roeder  
samjesse: And how would you convert from tf to ENUM_TIMEFRAMES? as I am getting an error when the tf in used in some function parameters expecting ENUM_TIMEFRAMES.

The values are the same, so just cast it.

To add comments, please log in or register