MT4
任意货币对自动添加止损和平包
回复:0  浏览:401
  • 楼主admin 圈主
  • 2019-05-05 11:51
1. 在任意一个k线窗口运行,对所有挂单和持仓单有效
2. 如果发现未设置止损,则添加止损。
3.如果浮盈超过一定点数,自动平保。
4. 手动调整止损后本ea不再起作用

参数:   1. 平保点数
            2. 止损点数
            3. 止盈点数

  1. //+------------------------------------------------------------------+
  2. //|                                                     MoveEven.mq4 |
  3. //|                       Copyright ?2011, metaQuotes Software Corp. |
  4. //+------------------------------------------------------------------+
  5. #property copyright "Copyright ?2011, metaQuotes Software Corp."

  6. extern int PointWin = 50;
  7. extern int TakeProfit = 200;
  8. extern int StopLoss = 35;
  9. int        PointScale = 10; //在5位小数点报价平台为10,在4位小数点报价平台为1
  10. //+------------------------------------------------------------------+
  11. //| expert initialization function                                   |
  12. //+------------------------------------------------------------------+
  13. int init()
  14.   {
  15. //----
  16. //----
  17.    return(0);
  18.   }
  19. //+------------------------------------------------------------------+
  20. //| expert deinitialization function                                 |
  21. //+------------------------------------------------------------------+
  22. int deinit()
  23.   {
  24. //----
  25. //----
  26.    return(0);
  27.   }
  28. //+------------------------------------------------------------------+
  29. //| expert start function                                            |
  30. //+------------------------------------------------------------------+
  31. int start()
  32.   {
  33. //----
  34. //调整止损
  35. if(OrdersTotal()>0)
  36. {
  37.    ChangeStopLoss();
  38. }     
  39. //----
  40.    return(0);
  41.   }
  42.   
  43.    void ChangeStopLoss ()
  44. {
  45.     int i;

  46.     for(i = OrdersTotal()-1; i>=0; i--)
  47.     {
  48.        OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  49.        int tick = OrderTicket();
  50.        double point = MarketInfo(OrderSymbol(), MODE_POINT);
  51.        if((OrderType()==OP_BUY )|| (OrderType()==OP_BUYLIMIT))
  52.        {
  53.          if(OrderStopLoss()== 0)
  54.          {
  55.             if(OrderModify(tick, OrderOpenPrice(), (OrderOpenPrice()- StopLoss*PointScale*point), (OrderOpenPrice()+ TakeProfit*PointScale*point ),0, Red))
  56.             {
  57.                Print("++++++++++Currency pair: ", Symbol(), "  Add StopLoss to ticket: ", tick, " successfully!!!");
  58.                Sleep(5000);
  59.                }
  60.          }
  61.          else if( (Bid > (OrderOpenPrice()+PointWin*PointScale*point))&&  (OrderStopLoss()<OrderOpenPrice()) && (OrderType()==OP_BUY ) )
  62.          {
  63.             if(OrderModify(tick, OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(),0, Red))
  64.             {
  65.                Print("*********Currency pair: ", OrderSymbol(), "  MoveEvento ticket: ", tick, " successfully!!!");
  66.                Sleep(5000);
  67.             }
  68.          }
  69.         } else
  70.         if((OrderType() == OP_SELL) || (OrderType() == OP_SELLLIMIT))
  71.         {
  72.          if(OrderStopLoss()== 0)
  73.          {
  74.             if(OrderModify(tick, OrderOpenPrice(), (OrderOpenPrice()+ StopLoss*PointScale*point), (OrderOpenPrice()- TakeProfit*PointScale*point ),0, Red))
  75.             {
  76.                Print("++++++++++Currency pair: ", OrderSymbol(), "  Add StopLoss to ticket: ", tick, " successfully!!!");
  77.                Sleep(5000);
  78.             }
  79.          }
  80.          else if( (Ask < (OrderOpenPrice()-PointWin*PointScale*point )) && (OrderStopLoss()>OrderOpenPrice()) && (OrderType() == OP_SELL))
  81.          {
  82.             if(OrderModify(tick, OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(),0, Red))
  83.             {
  84.                Print("*********Currency pair: ", OrderSymbol(), "  MoveEvento ticket: ", tick, " successfully!!!");
  85.                Sleep(5000);
  86.             }
  87.          }
  88.         }
  89.     }
  90. }

  91. //+------------------------------------------------------------------+