An iterable variable declaration

 

Can I declare variables in a loop, each with a different name?

for(int i=0; i<OrdersTotal(); i++)
  {
   if(OrderSelect(i, SELECT_BY_POS))
     {
      double var + OrderTicket() = OrderOpenPrice()
     }
  }

So I would end up with a variable for each order ie.

varXXXXXXXX = 1.2548

varYYYYYYYY = 0.8849

varZZZZZZZZ = 110.48

Any help or guidance would be appreciated.

 
Use an Array
 
colombodave:

Can I declare variables in a loop, each with a different name?

So I would end up with a variable for each order ie.

varXXXXXXXX = 1.2548

varYYYYYYYY = 0.8849

varZZZZZZZZ = 110.48

Any help or guidance would be appreciated.

You need to use a mapping object, i.e. a dictionary/hash-map. 


CHashMap<int, double> top;

for(int i=0; i<OrdersTotal(); i++)
   if(OrderSelect(i, SELECT_BY_POS))
      top.Add(OrderTicket(), OrderOpenPrice());