移动止损功能

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

  1. for(i = 0; i < OrdersTotal(); i++)
  2. { // 1
  3. OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  4. // Trail Long / Buy
  5. if ( (OrderType() == OP_BUY) && (OrderMagicNumber() == magic) )
  6. { // 2
  7. if ( (OrderClosePrice() - OrderOpenPrice()) > (TrailingStop*Point) )
  8. { // 3
  9. if ( OrderStopLoss() < (OrderClosePrice() - TrailingStop*Point) )
  10. { // 4
  11. OrderModify(OrderTicket(),
  12. OrderOpenPrice(),
  13. OrderClosePrice() - TrailingStop*Point,
  14. OrderTakeProfit(),
  15. Orchid);
  16. } // 4
  17. } // 3
  18. } // 2
  19. // Trail Short / Sell
  20. if ( (OrderType() == OP_SELL) && (OrderMagicNumber() == magic) )
  21. { // 2
  22. if ( (OrderOpenPrice() - OrderClosePrice()) > (TrailingStop*Point) )
  23. { // 3
  24. if ( (OrderStopLoss() > (OrderClosePrice() + TrailingStop*Point)) ||
  25. (OrderStopLoss() == 0) )
  26. { // 4
  27. OrderModify(OrderTicket(),
  28. OrderOpenPrice(),
  29. OrderClosePrice() + TrailingStop*Point,
  30. OrderTakeProfit(),
  31. Orchid);
  32. } // 4
  33. } // 3
  34. } // 2
  35. } // 1
  36. //+- End of trading control -----------------------------------------------------------------+
  37. } // B if (UserAcceptsAllLiability == true)
  38. return(0);
  39. } // A init start()
打赏