mar:
Populate the arrays dependant on the settings of the 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:
But now I would like to use extern variables to determine which timeframes should be used like this:
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?
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!!
mar:
A last question... I just read about the function of init() and deinit(). Can I populate the array in the init()?
Yes.
A last question... I just read about the function of init() and deinit(). Can I populate the array in the init()?
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... :)

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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??