|
//-请帮我改下,只需加载一个窗口,下单时对所有订单扫描,没有的止损和止盈的单子,自动添加止损止盈。。 //-改好后传给我,在线等,谢谢了。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,万分感谢!!! |
EA发布区