持仓订单的移动止损

楼主  收藏   举报   帖子创建时间:  2019-05-05 14:33 回复:0 关注量:932
函数执行持仓订单的移动止损功能。

  1. extern int Magic = 20080829;
  2. extern color clModify = Silver;
  3. extern int TrailingStart = 30;
  4. extern int TrailingSize = 30;
  5. void TrailPositions()
  6. {
  7. int cnt = OrdersTotal();
  8. for (int i=0; i<cnt; i++)
  9. {
  10. if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
  11. if (OrderSymbol() != Symbol()) continue;
  12. if (OrderMagicNumber() != Magic) continue;
  13. int type = OrderType();
  14. if (type == OP_BUY)
  15. {
  16. if (Bid-OrderOpenPrice() > TrailingStart*Point)
  17. {
  18. if (OrderStopLoss() < Bid - (TrailingSize+1)*Point)
  19. {
  20. OrderModify(OrderTicket(),
  21. OrderOpenPrice(),
  22. Bid-TrailingSize*Point,
  23. OrderTakeProfit(), 0, clModify);
  24. }
  25. }
  26. }
  27. if (type == OP_SELL)
  28. {
  29. if (OrderOpenPrice()-Ask > TrailingStart*Point)
  30. {
  31. if (OrderStopLoss() > Ask + (TrailingSize+1)*Point || OrderStopLoss() == 0)
  32. {
  33. OrderModify(OrderTicket(),
  34. OrderOpenPrice(),
  35. Ask+TrailingSize*Point,
  36. OrderTakeProfit(), 0, clModify);
  37. }
  38. }
  39. }
  40. }
  41. }
打赏