# two orders. close one!

120

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<total;cnt++)
{
{
if(OrderType()==OP_SELL)
{
double stnewpriceshell = OrderOpenPrice();
double stshell = OrderStopLoss();

if(stshell<=0 && Bid-20*MyPoint<stnewpriceshell)
{
modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewpriceshell-10*MyPoint,0,0,clrLightCyan);
}

}//FIM OPSHELL

```
Moderator
12394

```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 Variables

Check the condition of one and if condition is true, close the other.

120

I tried several times as you said, but could not.

```//GLOBAL VAR
int modify;
int ticket;

//FIM GLOBAL VAR
if(TotalOrdersCount()<2)
{

}

int cnt, total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
{
double stnewprice = OrderOpenPrice();
if(stnewprice< stnewprice+20*MyPoint)
{
modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewprice+20*MyPoint,0,0,clrLightGreen);

}

}
}

}

}```

THANKS FOR HELPING ME

Moderator
12394

`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);

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)
`     if(modify==1) int close = OrderClose(ticketbuy2,Lots,Ask,0,0);`