|
Close all pending and open order when 1 trade hit TP
Hi,
I'm trying to write a codes in my EA that will close all pending and open orders once there is 1 trade that hit TP. Below is the codes that I used, seems not working. Can somebody take a look and advise what is missing. Thanks.
if( PreviousOpenOrders > OpenOrders )
{
for( cnt = OrdersTotal()-1; cnt >= 0; cnt-- )
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode = OrderType();
if( OrderSymbol() == Symbol() &&
OrderMagicNumber()==Magic)
{
if( mode == OP_BUY ) OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Blue);
if( mode == OP_SELL ) OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Red);
if (mode == OP_SELLLIMIT) OrderDelete(OrderTicket());
if (mode == OP_BUYLIMIT) OrderDelete(OrderTicket());
}
}
}
}
|