函数执行持仓单全部平仓及挂单全部删除。
- int CloseEverything()
- {
- double myAsk;
- double myBid;
- int myTkt;
- double myLot;
- int myTyp;
- int i;
- bool result = false;
- for(i=OrdersTotal();i>=0;i--)
- {
- OrderSelect(i, SELECT_BY_POS);
- myAsk=MarketInfo(OrderSymbol(),MODE_ASK);
- myBid=MarketInfo(OrderSymbol(),MODE_BID);
- myTkt=OrderTicket();
- myLot=OrderLots();
- myTyp=OrderType();
- switch( myTyp )
- {
- //Close opened long positions
- case OP_BUY :result = OrderClose(myTkt, myLot, myBid, Slippage, Red);
- break;
- //Close opened short positions
- case OP_SELL :result = OrderClose(myTkt, myLot, myAsk, Slippage, Red);
- break;
- //Close pending orders
- case OP_BUYLIMIT :
- case OP_BUYSTOP :
- case OP_SELLLIMIT:
- case OP_SELLSTOP :result = OrderDelete( OrderTicket() );
- }
- if(result == false)
- {
- alert("Order " , myTkt , " failed to close. Error:" , GetLastError() );
- Print("Order " , myTkt , " failed to close. Error:" , GetLastError() );
- Sleep(3000);
- }
- Sleep(1000);
- } //for
- } // closeeverything
|