# Closing pending order, activating the opposite order

29
2015.06.01 19:42

I need to close the pending order, when is activated reverse pending order  - Active OP_BUY activates the close OP_SELLSTOP and vice versa.  How to define this condition?

for(p = 0; p< OrdersTotal(); p ++)

if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES)==true && OrderMagicNumber()==Magic_number)

if (OrderType ()==OP_BUYSTOP )  {close=OrderDelete( OrderTicket());}

for(p = 0; p< OrdersTotal(); p ++)

if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES)==true && OrderMagicNumber()==Magic_number)

if (OrderType ()==OP_SELLSTOP )  {close=OrderDelete( OrderTicket());}

thx

29
2015.06.02 19:27

problem solved

for (p = 0; p < OrdersTotal(); p++)
{if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==Magic_number)
{if (OrderSymbol() == Symbol())
{if (OrderType() == OP_BUY ) buy++; if (OrderType() == OP_SELL) sell++;    } } }
if (buy > 0) {for (p = 0; p < OrdersTotal(); p++)
{if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==Magic_number)
{if (OrderSymbol() == Symbol())
{if  (OrderType() == OP_SELLSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }
if (sell > 0) {for (p = 0; p < OrdersTotal(); p++)
{if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==Magic_number)
{if (OrderSymbol() == Symbol())
{if (OrderType() == OP_BUYSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }