持仓单全部平仓及删除全部挂单

楼主  收藏   举报   帖子创建时间:  2019-05-05 14:33 回复:0 关注量:451
函数执行持仓单全部平仓及挂单全部删除。

  1. int CloseEverything()
  2. {
  3. double myAsk;
  4. double myBid;
  5. int myTkt;
  6. double myLot;
  7. int myTyp;
  8. int i;
  9. bool result = false;
  10. for(i=OrdersTotal();i>=0;i--)
  11. {
  12. OrderSelect(i, SELECT_BY_POS);
  13. myAsk=MarketInfo(OrderSymbol(),MODE_ASK);
  14. myBid=MarketInfo(OrderSymbol(),MODE_BID);
  15. myTkt=OrderTicket();
  16. myLot=OrderLots();
  17. myTyp=OrderType();
  18. switch( myTyp )
  19. {
  20. //Close opened long positions
  21. case OP_BUY :result = OrderClose(myTkt, myLot, myBid, Slippage, Red);
  22. break;
  23. //Close opened short positions
  24. case OP_SELL :result = OrderClose(myTkt, myLot, myAsk, Slippage, Red);
  25. break;
  26. //Close pending orders
  27. case OP_BUYLIMIT :
  28. case OP_BUYSTOP :
  29. case OP_SELLLIMIT:
  30. case OP_SELLSTOP :result = OrderDelete( OrderTicket() );
  31. }
  32. if(result == false)
  33. {
  34. alert("Order " , myTkt , " failed to close. Error:" , GetLastError() );
  35. Print("Order " , myTkt , " failed to close. Error:" , GetLastError() );
  36. Sleep(3000);
  37. }
  38. Sleep(1000);
  39. } //for
  40. } // closeeverything
打赏