English

## two orders. close one!

 41 KeepMarcos 2016.03.15 00:58   People thanks very much for the help.you help a lot and i am very grateful for the help in my learning. In my studies, I'm trying to terminate an order if another order is closed. Example SHELL: if Order(1) OrderOpenPrice()-20PIPS then Order(2) CLOSE.I can not imagine how to program!please, I'm very doubts to solve. ```if(TotalOrdersCount()<2 && TotalOrdersCount()==0)       {          ticket   =    OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,NULL,MagicNumber,0,Blue);       ticket++;              ticket =    OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,NULL,MagicNumber,0,Red);       ticket++;          } int cnt, total=OrdersTotal();       for(cnt=0;cnt
 Moderator3412 GumRai 2016.03.15 01:34 #   ```if(TotalOrdersCount()<2 && TotalOrdersCount()==0) //Doesn't make sense. It is the same as if(TotalOrdersCount()==0)       ticket++;   //Why?       ticket++;   //Why?```Save the 2 ticket numbers as Global VariablesCheck the condition of one and if condition is true, close the other.
 41 KeepMarcos 2016.03.16 16:16 #   thanks for answering Gumrai.I tried several times as you said, but could not.  ```//GLOBAL VAR int modify; int ticketbuy,ticketshell; int ticket; //FIM GLOBAL VAR         if(TotalOrdersCount()<2)       {          ticket   =    OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Blue);       ticketbuy = OrderTicket();                     ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Red);       ticketbuy2 = OrderTicket();       }                 int cnt, total=OrdersTotal();       for(cnt=0;cnt
 Moderator3412 GumRai 2016.03.16 21:00 #   `int modify;`You should get into the habit of declaring variables correctly. modify is used as a bool, so should be declared as a bool.Also, I don't see that it is necessary to declare it Globally as once it is set to true, it will remain true during subsequent ticks. This could result in trades being closed as soon as they are opened.```      ticket   =    OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Blue);       ticketbuy = OrderTicket();                     ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Red);       ticketbuy2 = OrderTicket();```No order has been selected, so OrderTicket() should not be used here.```      ticket   =    OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Blue);       if(ticket>0)         ticketbuy = ticket;                     ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,NULL,MagicNumber,0,Red);       if(ticket>0)          ticketbuy2 = ticket;   ````     if(modify==1) int close = OrderClose(ticketbuy2,Lots,Ask,0,0);`A Buy is closed at Bid, not Ask