//--------------------------------------------------------------------- // Closes all market orders. //--------------------------------------------------------------------- #property copyright "© RickD 2006-2007" #property link "www.e2e-fx.net" //--------------------------------------------------------------------- // Slippage is the maximum allowable slippage value in points. //--------------------------------------------------------------------- int Slippage = 3; void CloseOrders() { int cnt = OrdersTotal(); for (int i=cnt-1; i >= 0; i--) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; //if (OrderSymbol() != Symbol()) continue; //if (OrderMagicNumber() != Magic) continue; if (OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage); } if (OrderType() == OP_SELL) { OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage); } } }