assign 5 differents order open price to 5 local variables

Back to topics list To post a new topic, please log in or register
avatar
41
itriad 2016.04.27 02:41
 
Hello, I have a problem to assign values to different local variable, I have 5 position open at different prices but
my script gives the same value to 5 different variables
Where is the problem??? thank you for any help
avatar
Moderator
3416
GumRai 2016.04.27 02:47 #
 
As you don't show any code, how can we know?
avatar
41
itriad 2016.04.27 02:48 #
 
//---
   double    orders1=0;//first order open price 
   double    orders2=0;//second order open price 
   double    orders3=0;//third order open price 
   double    orders4=0;//fourth order open price 
   double    orders5=0;// etc etc etc etc


     {
      for(int i=0; i<OrdersTotal(); i++)

         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
           {
            if(orders1==0){orders1=OrderOpenPrice();}// my open price is 1.13104
            if(orders2==0){orders2=OrderOpenPrice();}// my open price is 1.13053
            if(orders3==0){orders3=OrderOpenPrice();}// my open price is 1.13105
            if(orders4==0){orders4=OrderOpenPrice();}// my open price is 1.13032
            if(orders5==0){orders5=OrderOpenPrice();}// my open price is 1.13075
           }

     }
   Print("orders1 --> ",orders1);// here is my problem all the variable have the same value??
   Print("orders2 --> ",orders2);
   Print("orders3 --> ",orders3);
   Print("orders4 --> ",orders4);
   Print("orders5 --> ",orders5);

avatar
41
itriad 2016.04.27 02:52 #
 

2016.04.27 02:30:56.399 Script loop #ENM6,M5: removed

2016.04.27 02:30:56.399 loop #ENM6,M5: uninit reason 0

2016.04.27 02:30:56.399 loop #ENM6,M5: orders5 --> 1.12981

2016.04.27 02:30:56.399 loop #ENM6,M5: orders4 --> 1.12981

2016.04.27 02:30:56.399 loop #ENM6,M5: orders3 --> 1.12981

2016.04.27 02:30:56.399 loop #ENM6,M5: orders2 --> 1.12981

2016.04.27 02:30:56.399 loop #ENM6,M5: orders1 --> 1.12981








avatar
41
itriad 2016.04.27 02:55 #
 
thank you for any help
avatar
Moderator
3416
GumRai 2016.04.27 03:31 #
 
   if(orders1==0)
     {
     orders1=OrderOpenPrice();
     continue;
     }

and do the same for every if in the loop


avatar
41
itriad 2016.04.27 03:44 #
 
thank you very much it works
avatar
41
itriad 2016.04.27 12:44 #
 
I'm a little confused with the "continue" method,
how to do without the "continue" if possible?
thank you all
avatar
12995
WHRoeder 2016.04.27 14:57 #
 
itriad: how to do without the "continue" if possible?
  1.       if(      orders1==0){orders1=OrderOpenPrice();}// my open price is 1.13104
          else  if(orders2==0){orders2=OrderOpenPrice();}// my open price is 1.13053
          else  if(orders3==0){orders3=OrderOpenPrice();}// my open price is 1.13105
          else  if(orders4==0){orders4=OrderOpenPrice();}// my open price is 1.13032
          else  if(orders5==0){orders5=OrderOpenPrice();}// my open price is 1.13075

  2. Or handle the general case
       double    orders{];  int nOrders=0
          for(int i=0; i<OrdersTotal(); i++) if(
             OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) // See note
          {
             ArrayResize(orders, nOrders + 1);
             orders[nOrders++] = OrderOpenPrice();
          }
       Print("orders1 --> ",orders[1);
       Print("orders2 --> ",orders[2];
       Print("orders3 --> ",orders[3];
       Print("orders4 --> ",orders[4];
       Print("orders5 --> ",orders[5];
    Note: No filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
avatar
41
itriad 2016.04.27 15:26 #
 
it works, a big thank you especially to WHroeder and Gumrai
avatar
41
itriad 2016.04.27 15:53 #
 
   double    orders[];  int nOrders=0;
   for(int i=0; i<OrdersTotal(); i++)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) // See note
        {
         ArrayResize(orders,nOrders+1);
         orders[nOrders++]=OrderOpenPrice();
        }
   Print("orders1 --> ",orders[0]);// <--- 1  if i start to 1, i have array out of range in 'loop.mq4' (26,31)
   Print("orders2 --> ",orders[1]);// <--- 2
   Print("orders3 --> ",orders[2]);// <--- 3
   Print("orders4 --> ",orders[3]);// <--- 4
   Print("orders5 --> ",orders[4]);// <--- 5
  }
it works perfectly thanks again
Back to topics list  

To add comments, please log in or register