📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    为啥在止损止盈的EA中,总是被自动平掉一部分仓位?

    2025-02-05 · 1106 阅读
    这个EA会自动平掉一部分仓位,明明已经FALSE了,但是没用。请教一下,需要添加啥才能禁止它自动平掉一部分仓位?


    //+------------------------------------------------------------------+
    //|                     自动止损、止盈、盈利后移动止损、分批出场.mq4 |
    //|                                      Copyright ?2009, 龙德而隐者 |
    //|                                                                  |
    //+------------------------------------------------------------------+
    //#property copyright "Copyright 2009 by 龙德而隐者"
    //#property link      "http://www.metaquotes.net/"
    extern string 自动止损参数="-----";
    extern bool AutoStoploss=True;
    extern double stoploss= 300;
    extern string 自动止盈参数="-----";
    extern bool AutoTakeProfit=True;
    extern double takeprofit=150;
    extern string 盈利后移动止损="-----";
    extern bool AutoTrailingStop=True;
    extern double TrailingStop = 300;
    extern string 分次离场参数="按比例分步撤退";
    extern bool Gradually = False;               
    extern int GraduallyNum = 3;               
    double OriginalLot;
    //+------------------------------------------------------------------+
    //| expert start function                                            |
    //+------------------------------------------------------------------+
    int start()
    {
    for(int cnt=0;cnt<OrdersTotal();cnt++)  
    {
    if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
    {

      if(OrderSymbol()==Symbol())
      {
         double stp=OrderStopLoss();   
         double tpt=OrderTakeProfit();  
         double OpenPrice = OrderOpenPrice();

           if (OriginalLot == 0)
               {
               OriginalLot=OrderLots();
               }         


         if(OrderType()==OP_BUY)         
         {
            CraduallyBuy ();
                if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0)   
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,Ask+Point*takeprofit,0,Green);
            else
            {
              if (AutoStoploss && stp==0)                  
              {
                OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,OrderTakeProfit(),0,Green);
                  }
          
                  if (AutoTakeProfit && tpt==0)               
              {
                OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+Point*takeprofit,0,Green);
              }   


              if (AutoTrailingStop  && ((Bid - OpenPrice) > Point*TrailingStop))      
              {
                if((Bid-stp)>TrailingStop*Point )
                OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
              }
                }   
         }

      if(OrderType()==OP_SELL)                  
      {
         CraduallySell ();
         if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0)  
           OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,Bid-Point*takeprofit,0,Green);
         else
         {
            if (AutoStoploss && stp==0)         
            {
                OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,OrderTakeProfit(),0,Green);
            }
            if (AutoTakeProfit && tpt==0)        
            {
                OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*takeprofit,0,Green);
            }  

            if(AutoTrailingStop  && ((OpenPrice-Ask) > Point*TrailingStop ))      
            {
                       if((stp-Ask)>TrailingStop*Point)
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Green);
            }
         }
      }

    }
    }
    else
    {
        OriginalLot=0;
    }
             
    }
    }





    void CraduallyBuy ()               
    {
      double OpenPrice = OrderOpenPrice();
      double lot=OrderLots();            
      
      for (int yi=1;yi<=GraduallyNum;yi++)
       {
              if (NormalizeDouble((Bid - OpenPrice)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0))
                {
            
            if  (lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2))
             {
               OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Bid,3,CLR_NONE);
             }
                         
                }
            }
    }



    void CraduallySell ()               
    {
      double OpenPrice = OrderOpenPrice();
      double lot=OrderLots();            
      
      for (int yi=1;yi<=GraduallyNum;yi++)
       {
              if (NormalizeDouble((OpenPrice - Ask)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0))
                {            
            
            if  (lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2))
             {
               OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Ask,3,CLR_NONE);
             }
                         
                }
            }

    }


    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 4 个

    m1800 LV9

    发表于 2025-2-5 22:23:47 | 显示全部楼层

    extern bool Gradually = False
    这个设置开关并没有生效,在整个代码中没有体现这个开关.
    可以加在CraduallyBuy () 和CraduallySell ()  的开头部分.
    if (Gradually==false)
    return;

    正911737 LV5

    发表于 2025-2-8 20:05:24 | 显示全部楼层

    m1800 发表于 2025-2-5 22:23
    extern bool Gradually = False
    这个设置开关并没有生效,在整个代码中没有体现这个开关.
    可以加在Cradual ...

    非常感谢!
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服