Hi guys
I am writing an indicator where the user defines which currencies to be used
extern string Currency1="EURUSD";
extern string Currency2="GBPUSD";
extern string Currency3="USDCHF";
.
.
.
extern string Currency13="EURNZD";
extern string Currency14="GBPCAD";
then these currency names are stored into an array
currencyString[0]=Currency1;
currencyString[11]=Currency12;.
.
.
currencyString[12]=Currency13;
my question is rather than assigning values to the array one by one is there a way to apply a loop to do that, given the variable names are common
for example
for (int i=0; i<13; i++){
currencyString[i]=Currency +(i+1);
}
the above of course will return an error as Currency is not defined.
If there is a way to concatenate text ("Currency" +i) and then look if there is a variable that has that name problem is solved.
Thank you
for (int i=0; i<SymbolsTotal(1); i++){ currencyString[i]=SymbolName(i,1); }
for (int i=0; i<SymbolsTotal(1); i++){ currencyString[i]=SymbolName(i,1)+IntegerToString(i+1)); }
Thank you
It may be able to work, but only because there is a function in MQL5 that looks the order of symbols in the market watch.
However I wish to know if there is a way to write a string and see if there is a variable with that string and return its value.
StringFind()
StringFind() searches to see if a substring exists within a string.
What I want is to specify a string, see if a variable exists with that string and return its value
I dont get it.
The string is the variable ? what more can it return but it's name/position ?
Then you simply loop over
WHOLE_ARRAY
And if it's a match you know it's location.
Answer to OP question is NO but here is one other idea:
extern string DCDCurrencies="EURUSD,,USDJPY,,GBPUSD"; //then you can loop the string segments in to an arrayPersonally I'd just go with your original code though.
I dont get it.
The string is the variable ? what more can it return but it's name/position ?
Then you simply loop over
And if it's a match you know it's location.
Answer to OP question is NO but here is one other idea:
Personally I'd just go with your original code though.Thank you Benjamin
Is not very user friendly however.
I just wanted to know if it can be done , for educational purposes and cleaning up the code, as I get faced with this quite often.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys
I am writing an indicator where the user defines which currencies to be used
extern string Currency1="EURUSD";
extern string Currency2="GBPUSD";
extern string Currency3="USDCHF";
.
.
.
extern string Currency13="EURNZD";
extern string Currency14="GBPCAD";
then these currency names are stored into an array
currencyString[0]=Currency1;
currencyString[11]=Currency12;currencyString[12]=Currency13;
my question is rather than assigning values to the array one by one is there a way to apply a loop to do that, given the variable names are common
for example
for (int i=0; i<13; i++){
currencyString[i]=Currency +(i+1);
}
the above of course will return an error as Currency is not defined.
If there is a way to concatenate text ("Currency" +i) and then look if there is a variable that has that name problem is solved.
Thank you