put TimeFrame into variable?

 

Is there a way to put a TimeFrame into a variable?

int myFunc(TimeFrame aa)
   {
      return(iBars(Null,aa));
   }
      
 
Yep, have a read here: https://docs.mql4.com/constants/timeframes aa would be an int.
 
You misunderstood me. I know that the timeframes are. I want to have a parameter in my function receive a timeframe and use it in an internal function. Currently all I can do is pass the value of Period().
RaptorUK:
Yep, have a read here: https://docs.mql4.com/constants/timeframes aa would be an int.
You misunderstood me. I know what the timeframes are. I want to have a parameter in my function receive a timeframe and use it in an internal function.
 
FoxGuy:
You misunderstood me. I know that the timeframes are. I want to have a parameter in my function receive a timeframe and use it in an internal function. Currently all I can do is pass the value of Period().

Maybe I still misunderstand what you are asking . . . do you mean this ?

int bb = 60;  // H1

int num_bars = myFunc(bb);

int myFunc(int aa)
   {
      return(iBars(Null,aa));
   }
 
RaptorUK:

Maybe I still misunderstand what you are asking . . . do you mean this ?

Nope. This is a very simple sample of what I want to do:

int myFunc()
   {
      int iM15 = GetBarCount(Period_M15);
      int iH4 = GetBarCount(Period_H4);
      Print(iM15, iH4);
      return(0);
   }

int GetBarCount(TimeFrame p)
   {
      return(iBars(NULL,p));
   }
In reality I want to do things more complicated. My problem is that there is no type "TimeFrame". I'm hoping someone has figured out a way to do what I want.
 
int myFunc()
   {
      int iM15 = GetBarCount(Period_M15);
      int iH4 = GetBarCount(Period_H4);
      Print(iM15, iH4);
      return(0);
   }

int GetBarCount(int p)
   {
      return(iBars(NULL,p));
   }
 
FoxGuy:

Nope. This is a very simple sample of what I want to do:

In reality I want to do things more complicated. My problem is that there is no type "TimeFrame". I'm hoping someone has figured out a way to do what I want.

Hence . . .

RaptorUK:
Yep, have a read here: https://docs.mql4.com/constants/timeframes aa would be an int.
 
zzuegg:

Dang, I should have thought of that.

Thanks.

 
Period_M15, Period_H4, etc. are Constants, they get replaced with their numeric, int, equivalents at compile time.
 
RaptorUK:
Period_M15, Period_H4, etc. are Constants, they get replaced with their numeric, int, equivalents at compile time.
It never occurred to me that I could replace "iBars(NULL,Period_H4)" with "iBars(NULL,240)", so I never tested it.
 

or

 int TimeFrame[3]={PERIOD_M15,PERIOD_H1,PERIOD_H4};
/int myFunc()
   {
      int iM15 = GetBarCount(TimeFrame[0]);
      int iH4 = GetBarCount(TimeFrame[2]);
      Print(iM15, iH4);
      return(0);
   }

int GetBarCount(int p)
   {
      return(iBars(NULL,p));
   }/+------------------------------------------------------------------+
Reason: