找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 12|回复: 0

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

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-23 00:17:00 | 显示全部楼层 |阅读模式
盈利30点将止损提高到盈利15点处。这种操作,有时候也叫平保,为了避免将盈利的单子变亏损了所做的一个保护。这种操作非常有用,很多人都会用到,通过编写ea来实现这种功能,非常简单,短短几十行代码就能实现。下面是这个程序的全部代码,感兴趣可以复制下去保存为EA就可以运行。/

/+------------------------------------------------------------------+

//|                               盈利30点将止损提高到盈利15点处.mq4 |

//|                                                             云开 |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "云开"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict


input 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);

                 }

              }

           }

        }

     }

  }

//+------------------------------------------------------------------+

复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-12 10:40 , Processed in 0.105355 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表