Download MetaTrader 5

Loop over variables (index)

To add comments, please log in or register
naclll
22
naclll  

Hi,

Can we append the prefix of a variable with an index: variable_name (index) in the aim of creating a loop over the index.

variable_name_1

variable_name_2

.

.

.

variable_name_N


for(int s=1; s<=SYMBOLS_COUNT; s++)
     {   
    ArrayResize(InputVector_Clos_P_(s),histo); /* How ? */

//ArrayResize(InputVector_Clos_P_1,histo); 
//ArrayResize(InputVector_Clos_P_2,histo); 
//ArrayResize(InputVector_Clos_P_3,histo); 
       
     } 

  Is there any operator as "&" in VBA por example? 

Thanks  

Alain Verleyen
Moderator
31198
Alain Verleyen  

It's not possible to change a variable name dynamically (in VBA neither anyway). You need to use an array.

What are you trying to achieve ?

GBWT094114
3342
GBWT094114  
From your code I can guess you are trying to loop into a list of symbols available to trade with the platform , and use it for multi trading currency.
Stanislav Korotky
18242
Stanislav Korotky  
Why not to use an array variable_name[]?
naclll
22
naclll  

Thank you guys for your responses.

The goal is simply to use variables in a loop and this by intervening only on the number of variables. 

@Alain : in VBA, i mean to use the variable like in the example 

For I = 1 To 2
    MsgBox ("y" & I)
Next I


 The aim is not to create variable but only use it, like in first example , i want to  resize those three vectors only 

@Stanislav: How we can apply array variable_name[] for the example below ? thanks in advance 

for(int s=1; s<=3; s++)
     {  
    ArrayResize(InputVector_Clos_P_(s),histo);

//ArrayResize(InputVector_Clos_P_1,histo);
//ArrayResize(InputVector_Clos_P_2,histo);
//ArrayResize(InputVector_Clos_P_3,histo);
      
     }
Stanislav Korotky
18242
Stanislav Korotky  
You may have a look at this article, specifically at the clause "Creating Multidimensional Arrays Using OOP". This is just one of possible solutions. Using operator[] overload you may mimic multidimentional arrays almost fully.
To add comments, please log in or register