support 发表于 2022-12-5 12:48:07

盈利30点将止损提高到盈利15点处(平保)

盈利30点将止损提高到盈利15点处。这种操作,有时候也叫平保,为了避免将盈利的单子变亏损了所做的一个保护。这种操作非常有用,很多人都会用到,通过编写ea来实现这种功能,非常简单,短短几十行代码就能实现。下面是这个程序的全部代码,感兴趣可以复制下去保存为EA就可以运行。//+------------------------------------------------------------------+//|                               盈利30点将止损提高到盈利15点处.mq4 |//|                                                             云开 |//|                                             https://www.mql5.com |//+------------------------------------------------------------------+#property copyright "云开"#property link      "https://www.mql5.com"#property version   "1.00"#property strictinput int tratp=300;//盈利多少点input int tp=150;//止损调高到盈利多少点//+------------------------------------------------------------------+//| Expert initialization function                                 |//+------------------------------------------------------------------+int OnInit(){//---//---   return(INIT_SUCCEEDED);}//+------------------------------------------------------------------+//| Expert deinitialization function                                 |//+------------------------------------------------------------------+void OnDeinit(const int reason){//---}//+------------------------------------------------------------------+//| Expert tick function                                             |//+------------------------------------------------------------------+void OnTick(){//---   int total=OrdersTotal();   for(int i=0; i<total; i++)   {      if(OrderSelect(i, SELECT_BY_POS))      {         if(OrderSymbol()==Symbol())         {            if(OrderType()==OP_BUY)            {               if(OrderStopLoss()<OrderOpenPrice()+tp*Point && OrderClosePrice()-OrderOpenPrice()>tratp*Point)               {                  bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+tp*Point, OrderTakeProfit(), 0);               }            }            if(OrderType()==OP_SELL)            {               if((OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-tp*Point) && OrderOpenPrice()-OrderClosePrice()>tratp*Point)               {                  bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-tp*Point, OrderTakeProfit(), 0);               }            }         }      }   }}//+------------------------------------------------------------------+

木兮 发表于 2024-1-7 10:17:25

分享的都值得点赞

醉红尘灬残月 发表于 2024-3-5 10:16:42

楼主66666
页: [1]
查看完整版本: 盈利30点将止损提高到盈利15点处(平保)