Array values from extern variables?

 

Hello Foum,

I use different timeframes in an indicator to make some calculations. At the moment I use all timeframes by creating two arrays like these:

string Timeframe[] = {"M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1"};
int TimeframeNo[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1};

But now I would like to use extern variables to determine which timeframes should be used like this:

bool M1  = true;
bool M5  = true;
bool M15 = true;
bool M30 = true;
bool H1  = true;
bool H4  = true;
bool D1  = true;
bool W1  = true;
But how can I create an array with external variables??
 
mar:

Hello Foum,

I use different timeframes in an indicator to make some calculations. At the moment I use all timeframes by creating two arrays like these:

But now I would like to use extern variables to determine which timeframes should be used like this:

But how can I create an array with external variables??
Populate the arrays dependant on the settings of the extern variables . . .
 
But how? I only know how to populate an array the way I did it in the example. But when the timeframes are optional, I have to check with if (M1==true) .... if (W1==true) and everytime it is true, the variable must be added to the array, am I right? But how can I add something to an array?
 
mar:
But how? I only know how to populate an array the way I did it in the example. But when the timeframes are optional, I have to check with if (M1==true) .... if (W1==true) and everytime it is true, the variable must be added to the array, am I right? But how can I add something to an array?

Yes, correct.

As an example . . .

string Timeframe[];



if(M1)
   {
   ArrayResize(TimeFrame, ArraySize(TimeFrame) + 1)
   TimeFrame(ArraySize(TimeFrame) - 1) = "M1";
   }
   
if(M5)
   {
   ArrayResize(TimeFrame, ArraySize(TimeFrame) + 1)
   TimeFrame(ArraySize(TimeFrame) - 1) = "M5";
   }
   
// etc.   
 
Great! Thanks, Raptor!!
 
A last question... I just read about the function of init() and deinit(). Can I populate the array in the init()?
 
mar:
A last question... I just read about the function of init() and deinit(). Can I populate the array in the init()?
Yes.
 

I did this in the init():

if (M1)
   {
      ArrayResize(Timeframe, ArraySize(Timeframe)+1);
      Timeframe(ArraySize(Timeframe)-1)="M1";
      ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1);
      TimeframeNo(ArraySize(TimeframeNo)-1)=PERIOD_M1;
   }

And string Timeframe[]; is defined as global. Same with int TimeframeNo[];


 
mar:

I did this in the init():

And string Timeframe[]; is defined as global. Same with int TimeframeNo[];


Typo in my code . . . it was meant as an example, not for you to copy & paste . . .

if(M1)
   {
   ArrayResize(TimeFrame, ArraySize(TimeFrame) + 1)
   TimeFrame[ArraySize(TimeFrame) - 1] = "M1";
   }
   
if(M5)
   {
   ArrayResize(TimeFrame, ArraySize(TimeFrame) + 1)
   TimeFrame[ArraySize(TimeFrame) - 1] = "M5";
   }



 
Yes, I see... :)
 
mar:
Yes, I see... :)

have you try this with the list pairs?

for example

string CurrPair [] = {"AUDCAD", "AUDCHF", "AUDJPY"}

How to make it as the TF mentioned

to have list with

extern .... and the list the pairs above

Reason: