下面两个函数分别平仓指定订单识别码的多单和空单。选定条件是订单类型和识别码。
- void CloseAllSell()
- {
- bool CAS = FALSE;
- for (int t=0; t<OrdersTotal(); t++)
- {
- cg=OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
- if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber )
- CAS = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
- }
- }
- void CloseAllBuy()
- {
- bool CAB = FALSE;
- for (int t=0; t<OrdersTotal(); t++)
- {
- cg=OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
- if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber)
- CAB = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
- }
- }
|