put TimeFrame into variable?

To add comments, please log in or register
Bill Morris
287
Bill Morris  

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

int myFunc(TimeFrame aa)
   {
      return(iBars(Null,aa));
   }
      
Simon Gniadkowski
17677
Simon Gniadkowski  
Yep, have a read here: https://docs.mql4.com/constants/timeframes aa would be an int.
Bill Morris
287
Bill Morris  
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.
Simon Gniadkowski
17677
Simon Gniadkowski  
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));
   }
Bill Morris
287
Bill Morris  
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.
zzuegg
1504
zzuegg  
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));
   }
Simon Gniadkowski
17677
Simon Gniadkowski  
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.
Bill Morris
287
Bill Morris  
zzuegg:

Dang, I should have thought of that.

Thanks.

Simon Gniadkowski
17677
Simon Gniadkowski  
Period_M15, Period_H4, etc. are Constants, they get replaced with their numeric, int, equivalents at compile time.
Bill Morris
287
Bill Morris  
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.
19730719
63
19730719  

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));
   }/+------------------------------------------------------------------+
12
To add comments, please log in or register