zell dincht
zell dincht

Reputation: 21

Timeframe as a variable, which declaration type?

I am working on a MQL4 expert advisor. This advisor uses 2 separate timeframes for its signals and entries/exits. Up until now I have used an "sinput" to allow the user to choose the desired timeframe for the higher timeframe indicators.

I would like to remove the option, and have the optimized pairs set automatically in my code. I am attempting to initiate a variable "IndicatorTF", and then later assign it a value of the desired timeframe.

Every other portion of my code runs just fine, however programmatically setting and changing timeframes is new to me.

If I try to initialize the variable "IndicatorHTF" globally and then actually set the value in "On Init" I get an error stating that I cannot change a constant. If, however, I set the "IndicatorHTF" variable directly in "On Init", just before it is actually used, I get a declaration error as I cant seem to find the correct type.

I realize its not a bool, int, double, or string, but I have no Idea what I should be using as a type.

What ive tried:
1)

//Globally
ENUM_TIMEFRAMES IndicatorHTF; //with sinput,bool,string,etc
int OnInit()
{
   if(Period()==PERIOD_M1){resolution=PERIOD_M5;}
}

2)

int OnInit()
{
   ENUM_TIMEFRAMES IndicatorHTF;  //with sinput,bool,string,etc
   if(Period()==PERIOD_M1){resolution=PERIOD_M5;}
}

Upvotes: 1

Views: 1623

Answers (1)

zell dincht
zell dincht

Reputation: 21

Fixed the issue, it was simply a placement issue. By setting

if(Period()==PERIOD_M1){IndicatorHTF=PERIOD_M5;}  

actually within my trade logic that used IndicatorHTF it was able to read and set the values correctly :)

Upvotes: 1

Related Questions