limit the periods in ENUM_TIMEFRAMES as input

 

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

 
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...
 

Something like

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

Something like

enum tf  
   { 
    H1=PERIOD_H1,    
    H4=PERIOD_H4
   };
Don't hardcode period values.
 
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 :)

 
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.

 
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.

Reason: