盈利后修改止损价为开仓价

楼主  收藏   举报   帖子创建时间:  2019-05-05 14:38 回复:0 关注量:41
该函数执行的是提损功能,即订单盈利到达水平后将止损价修改为开仓价,这样确保订单不会亏损出场。

  1. //这里函数带有开仓部分,调用时请自行过滤所需要的函数
  2. extern double 下单量=0.1;
  3. extern double 止损=30;
  4. extern double 止盈=90;
  5. extern double 滑点=3;
  6. extern double TrailingStop=20; //盈利的点数,你这里是 20
  7. int start()
  8. { int i;int ticket1;
  9. //+---------- 自定义做多条件 --------------------------------------------------------+
  10. if( OrdersTotal()==0
  11. && Close[1]-Open[1]>1*Point
  12. //+------------------------------------------------------------------+
  13. )
  14. {ticket1=OrderSend(Symbol(),OP_BUY, 下 单 量 ,Ask, 滑 点 ,Ask- 止 损
  15. *Point,Ask+止盈*Point,"",20101018,0,0);
  16. }
  17. if( OrdersTotal()==0
  18. && Open[1]-Close[1]>1*Point
  19. //+------------------------------------------------------------------+
  20. ){ticket1=OrderSend(Symbol(),OP_SELL, 下 单 量 ,Bid, 滑 点 ,Bid+ 止 损
  21. *Point,Bid-止盈*Point,"",20101018,0,0);
  22. }
  23. //+---------以下为当有利润 20 点时,调整止损位到入场价-----------------+
  24. int total=OrdersTotal();
  25. for(int cnt=0;cnt<total;cnt++)
  26. {
  27. OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  28. if(OrderType()<=OP_SELL && // check for opened position
  29. OrderSymbol()==Symbol()) // check for symbol
  30. {
  31. if(OrderType()==OP_BUY) // long position is opened
  32. {
  33. if(TrailingStop>0)
  34. {
  35. if(Bid-OrderOpenPrice()>Point*TrailingStop)
  36. {
  37. {
  38. OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
  39. return(0);
  40. }
  41. }
  42. }
  43. }
  44. else // go to short position
  45. {
  46. // should it be closed?
  47. if(TrailingStop>0)
  48. {
  49. if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
  50. {
  51. {
  52. OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
  53. return(0);
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. //+------------------------------------------------------------------+
  61. return(0);}
打赏