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

    //-请帮我改下,只需加载一个窗口,下单时对所有订单扫描,没有的止损和止盈的单子...

    2018-08-15 · 5800 阅读
    //-请帮我改下,只需加载一个窗口,下单时对所有订单扫描,没有的止损和止盈的单子,自动添加止损止盈。。
    //-改好后传给我,在线等,谢谢了。QQ515521313 或者邮箱515521313@qq.com,万分感谢!!!
    源码如下:
    //+------------------------------------------------------------------+
    //|                                         自动止盈止损分批出场.mq4 |
    //|                        Copyright 2018, MetaQuotes Software Corp. |
    //|                                             https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2018, MetaQuotes Software Corp."
    #property link      "https://www.mql5.com"
    #property version   "1.00"
    #property strict
    //-请高手帮我改下,只需加载一个窗口,下单时对所有订单扫描,没有的止损和止盈的单子,自动添加止损止盈。。
    //-改好后传给我,在线等,谢谢了。QQ515521313 或者邮箱515521313@qq.com
    #property copyright ""
    #property link      ""
    extern bool 智能系数止盈止损=True;
    extern int    TakeProfitxxx  =1;  // 止盈系数 1-2
    extern int    stoplossxxx  =3;   // 止盈系数 2-4
    extern int    TrailingStopxxx=2; // 移动止损系数 2-4
    extern string 自动止损参数="默认打开";
    extern bool AutoStoploss=True;
    extern double stoploss= 220;
    extern string 自动止盈参数="默认打开";
    extern bool AutoTakeProfit=True;
    extern double takeprofit=440;
    extern string 盈利后移动止损="默认打开";
    extern bool AutoTrailingStop=true;
    extern double TrailingStop = 330;
    extern string 分次离场参数="按比例分步撤退";
    extern bool Gradually = False;               
    extern int GraduallyNum = 3;               
    double OriginalLot;
    int    ADRofdays = 3;

    //+------------------------------------------------------------------+
    //| Expert initialization function                                   |
    //+------------------------------------------------------------------+
    int OnInit()
      {
        double MODTICKV=(MarketInfo(Symbol(),MODE_TICKVALUE)); //一标准手最小波动盈亏
       return(INIT_SUCCEEDED);
      }
    //+------------------------------------------------------------------+
    //| Expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
      {
    //---

      }
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    void OnTick()
      {
        int Auto_takeprofit= ADR_vlue()/TakeProfitxxx;
        int Auto_stoploss= ADR_vlue()/stoplossxxx;
        int Auto_TrailingStop= ADR_vlue()/TrailingStopxxx;

       if (智能系数止盈止损=True){ takeprofit=Auto_takeprofit;  stoploss=Auto_stoploss; TrailingStop=Auto_stoploss;}  
       else  stoploss= stoploss;  takeprofit=takeprofit;  TrailingStop=TrailingStop;
    for(int cnt=0;cnt<OrdersTotal();cnt++)  
    {
    if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
    {

      if(OrdersTotal()>0)
      {
          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)   
              double zz1=OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,Ask+Point*takeprofit,0,Green);
            else
            {
              if (AutoStoploss && stp==0)                  
              {
                double zz1=OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,OrderTakeProfit(),0,Green);
                  }

                  if (AutoTakeProfit && tpt==0)               
              {
                double zz1=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+Point*takeprofit,0,Green);
              }   


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

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

            if(AutoTrailingStop  && ((OpenPrice-Ask) > Point*TrailingStop ))      
            {
                       if((stp-Ask)>TrailingStop*Point)
                  double zz1=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))
             {
               double zz1=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))
             {
               double zz1=OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Ask,3,CLR_NONE);
             }
                         
                }
            }

    }

    //------------------------
    int ADR_vlue()  
    {
      double pnt = MarketInfo(Symbol(),MODE_POINT);
    //int dig = MarketInfo(Symbol(),MODE_DIGITS);
      int c=0,ADR=0;
      double sum=0;
      for (int i=1; i<Bars-1; i++)  
      {
        double hi = iHigh(NULL,PERIOD_D1,i);
        double lo = iLow(NULL,PERIOD_D1,i);
        datetime dt = iTime(NULL,PERIOD_D1,i);
        if (TimeDayOfWeek(dt) > 0 && TimeDayOfWeek(dt) < 6)  
         {
          sum += hi - lo;
          c++;
          if (c>=ADRofdays) break;
         }  

      }
          ADR =sum/c/pnt;

      if ( pnt>0)  
      {
       double  hi = iHigh(NULL,PERIOD_D1,1);
       double  lo = iLow(NULL,PERIOD_D1,1);
       // string objtext = "ADR = " + DoubleToStr(sum/c/pnt,0) + "  (" + DoubleToStr(c,0) + " days)"  ;  //   Yesterday = " + DoubleToStr((hi-lo)/pnt,0)
        string objtext = "日均幅度 = " + DoubleToStr(sum/c/pnt,0) + " point"  ;  //   Yesterday = " + DoubleToStr((hi-lo)/pnt,0)
        ObjectSet("ADRJG",OBJPROP_CORNER,3);
        ObjectSet("ADRJG",OBJPROP_XDISTANCE,20);
        ObjectSet("ADRJG",OBJPROP_YDISTANCE,20);
        ObjectSetText("ADRJG",objtext,9,"Arial Black",clrGold);
      }  
      return(ADR);
       //return(0);
    }  

    //-请帮我改下,只需加载一个窗口,下单时对所有订单扫描,没有的止损和止盈的单子,自动添加止损止盈。。
    //-改好后传给我,在线等,谢谢了。QQ515521313 或者邮箱515521313@qq.com,万分感谢!!!

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

    举报

     

    回答|共 15 个

    pengfajun LV3

    发表于 2020-2-14 12:20:56 | 显示全部楼层

    我是来刷分的,嘿嘿

    小名 LV3

    发表于 2020-3-12 11:55:29 | 显示全部楼层

    好好 学习了 确实不错

    云山游客 LV3

    发表于 2020-6-17 11:02:39 | 显示全部楼层

    :lol不错

    (_‵o′)凸 LV3

    发表于 2020-7-4 10:06:02 | 显示全部楼层

    谢谢楼主分享

    相依相伴 LV3

    发表于 2020-8-1 14:29:41 | 显示全部楼层

    谢谢楼主分享

    谢少 LV3

    发表于 2020-8-26 13:48:05 | 显示全部楼层

    谢谢楼主分享

    抱着回忆到老 LV3

    发表于 2020-9-3 16:25:56 | 显示全部楼层

    帮你顶下哈!!

    fx369 LV4

    发表于 2021-4-18 18:30:52 | 显示全部楼层

    帮你你顶顶

    hbzkysgm LV3

    发表于 2021-7-23 10:57:12 | 显示全部楼层

    支持下
    12下一页
    您需要登录后才可以回帖 登录 | 注册

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

    微信二维码

    有问题联系客服