2评论

1收藏

持仓订单的移动止损

avatar 老周 | 2374 人阅读 | 2 人评论 | 2017-03-27

函数执行持仓订单的移动止损功能。

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


""
还没有人打赏,支持一下

评论|共 2 个

sale

发表于 2019-10-20 17:16:16 | 显示全部楼层

fdjhtrsjtrkkzyrkstylkytdltdu

WUXIAODONG

发表于 2019-10-28 13:19:26 | 显示全部楼层

sale 发表于 2019-10-20 17:16
fdjhtrsjtrkkzyrkstylkytdltdu

13265656JJJH

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则