账户盈利到达预期全部平仓

楼主  收藏   举报   帖子创建时间:  2019-05-05 12:20 回复:0 关注量:246
该函数在账户盈利到达预期设定的值的时候执行全部平仓。

  1. int Save_Profit(){
  2. if (AccountProfit()>= Profit_to_Close)
  3. {
  4. for(int i=OrdersTotal()-1;i>=0;i--)
  5. {
  6. OrderSelect(i, SELECT_BY_POS);
  7. int type = OrderType();
  8. bool result = false;
  9. switch(type)
  10. {
  11. //Close opened long positions
  12. case
  13. OP_BUY
  14. :
  15. result
  16. =
  17. OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Pink);
  18. break;
  19. //Close opened short positions
  20. case
  21. OP_SELL
  22. :
  23. result
  24. =
  25. OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Pink);
  26. }
  27. if(result == false)
  28. {
  29. Sleep(3000);
  30. }
  31. else if (Cancel_Trading_On_Profit) cantrade=false;
  32. }
  33. Print ("Account Profit Reached. All Open Trades Have Been Closed");
  34. return(0);
  35. }
打赏