twostarii: I have string variables (Candle_1, Candle_2 etc..) which when printed returns "Red" or "Green" from a function. eg: When running: Print("**** Candle_1: "+Candle_1); Output is: **** Candle_1: Red
I would like to print values in a for loop for multiple candles but cant get the value of the variable returned:
for (int i=1;i<=Candle_Count;i++){ //string colour = Candle_+i; //option 1 //string colour = StringConcatenate("Candle_",i); //option 2 Print("**** colour: "+colour); }
I tried both option1 and option 2, neither work
- Please edit you existing post and use the "</>" icon (or Alt-S) from the posting toolbar to insert your code properly.
- MQL is a compiled language and not an interpreted language, so variable names cannot be composed at runtime.
- Instead of single variables, use an array. The following code sample is untested/uncompiled:
int Candle_Count = 5; // Number of Candles string Candle[Candle_Count]; // Declare an array of Candle_Count string elements // Example assignments of text to a string array element; Candle[0] = "Red"; Candle[1] = "Green"; // Printing out all the Candles for( int i = 0; i < Candle_Count; i++ ) { PrintFormat( "Candle %d Colour: %s", i, Candle[ i ] ); }

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
I have string variables (Candle_1, Candle_2 etc..) which when printed returns "Red" or "Green" from a function.
eg:
When running: Print("**** Candle_1: "+Candle_1);
Output is: **** Candle_1: Red
I would like to print values in a for loop for multiple candles but cant get the value of the variable returned:
for (int i=1;i<=Candle_Count;i++){
//string colour = Candle_+i; //option 1
//string colour = StringConcatenate("Candle_",i); //option 2
Print("**** colour: "+colour);
}
I tried both option1 and option 2, neither work