评论

收藏

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

avatar 老周 | 2148 人阅读 | 0 人评论 | 2017-03-27

函数执行持仓单全部平仓及挂单全部删除。

  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
复制代码


""
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则