
//+------------------------------------------------------------------+ //| disaster.mq4 | //| Max Fade | //| http:// | //+------------------------------------------------------------------+ #property copyright "Jimmy" #property link "http://blog.jimmyacrbin.com" extern double StopLoss = 200; extern double TakeProfit = 200; extern int ModelStyle = 1; extern int PeriodOption = 240; extern int BarJump = 1; extern int MAPER = 590; int Magic = 54321; datetime TradeTimeOut; datetime nowT; int init() { return(0); } int deinit() { return(0); } int start() { datetime LastTradeTimeOut; datetime CurrentTime; CurrentTime = TimeCurrent(); int preOrderType=-1,preTicket=0; double prePriceOpen=0,prePriceClose=0,preTP=0,preSL=0,a=0,b=0,g,h,aa,bb,rsiNum,volumNum,nowMa,preMa,prePreMa; bool STOPLEVELCHECK,res; int e,i,m,n,j,k,l,ticket,err,nBars=0,numOrdersCount=0,numSLCount=0,pass=1,t; int th,td,tl; double Price = 0.0; double StrategyProfit = 0.0; double nowOpenPrice = 0.0; double preHighPrice = 0.0,preLowPrice=0.0; double nowBhPrice = 0.0,nowBmPrice = 0.0,nowBlPrice = 0.0; double preBhPriceOne = 0.0,preBmPriceOne = 0.0,preBlPriceOne = 0.0; double preBhPriceTwo = 0.0,preBmPriceTwo = 0.0,preBlPriceTwo = 0.0; double nowClosePrice = 0.0,preClosePrice = 0.0,preOpenPrice = 0.0; double nowClosePriceH1 = 0.0,nowOpenPriceH1 = 0.0,preClosePriceH1 = 0.0,preOpenPriceH1 = 0.0; double tpreClosePriceH1 = 0.0,tpreOpenPriceH1 = 0.0; double ttpreClosePriceH1 = 0.0,ttpreOpenPriceH1 = 0.0; double prePreBhPriceOne = 0.0,prePreBmPriceOne = 0.0, prePreBlPriceOne = 0.0; int total=OrdersTotal(); int historyTotal = HistoryTotal(); //当前柱开盘价 nowOpenPrice = iOpen("EURUSD",PeriodOption,0); nowClosePrice = iClose("EURUSD",PeriodOption,0); preClosePrice = iClose("EURUSD",PeriodOption,1); preOpenPrice = iOpen("EURUSD",PeriodOption,1); preHighPrice = iHigh("EURUSD",PeriodOption,1); preLowPrice = iLow("EURUSD",PeriodOption,1); nowClosePriceH1 = iClose("EURUSD",PeriodOption,0); preClosePriceH1 = iClose("EURUSD",PeriodOption,1); tpreClosePriceH1 = iClose("EURUSD",PeriodOption,2); ttpreClosePriceH1 = iClose("EURUSD",PeriodOption,3); //当前布林带最高价 nowBhPrice = iBands("EURUSD",PeriodOption,20,2,0,4,1,0); //当前布林带最低价 nowBlPrice = iBands("EURUSD",PeriodOption,20,2,0,4,2,0); nowBmPrice = (nowBhPrice+nowBlPrice)/2; preBhPriceOne = iBands("EURUSD",PeriodOption,20,2,0,4,1,BarJump); preBlPriceOne = iBands("EURUSD",PeriodOption,20,2,0,4,2,BarJump); preBmPriceOne = (preBhPriceOne+preBlPriceOne)/2; preBhPriceTwo = iBands("EURUSD",PeriodOption,20,2,0,4,1,BarJump*2); preBlPriceTwo = iBands("EURUSD",PeriodOption,20,2,0,4,2,BarJump*2); preBmPriceTwo = (preBhPriceTwo+preBlPriceTwo)/2; nowMa = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0); preMa = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,2); prePreMa = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,4); //Print(nowBhPrice,nowBlPrice,preBhPriceOne,preBlPriceOne); double md = preMa-nowMa; //Print(md,"-",md-(preMa-nowMa),"-",preMa-nowMa,"-",nowOpenPrice,"-",Bid,"-",preMa-prePreMa,"-",NormalizeDouble(nowMa,6),"-",preMa,"-",prePreMa,"-",NormalizeDouble(Ask,6),"-",NormalizeDouble(Bid,6)); a = Ask - nowBmPrice ; aa = Ask - nowBhPrice ; b = nowBmPrice - Bid ; bb = nowBlPrice - Bid ; g = nowBmPrice - preBmPriceOne ; h = preBmPriceOne - preBmPriceTwo ; //当前小时数 th = TimeHour(TimeCurrent()); rsiNum = iRSI(NULL,0,14,PRICE_OPEN,0); volumNum = iVolume(NULL,PeriodOption,0); for (m=total;m>=0;m--){ if (OrderSelect(m,SELECT_BY_POS,MODE_TRADES)==false) continue; if(OrderProfit()<48){ if(OrderType()==0 && OrderStopLoss()<(Bid-Point*500)){ //Print("1开始修改止损2.",OrderTicket(),"---",OrderOpenPrice()); //res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+0.0002,OrderTakeProfit(),0,Blue); //res=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*40,Bid+Point*100,0,Blue); res=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*500,OrderTakeProfit(),0,Blue); //Bid-Point*TrailingStop_Buy if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } if(OrderType()==1 &&(OrderStopLoss()>(Ask+Point*500))){ Print("1开始修改止损2.",OrderTicket(),"---",OrderOpenPrice()); //res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-0.0002,OrderTakeProfit(),0,Blue); //res=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*40,Ask-Point*100,0,Red); res=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*500,OrderTakeProfit(),0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } }else{ if(OrderProfit()>=48&&OrderProfit()<100){ if(OrderType()==0 && OrderStopLoss()<=(Bid-Point*400)){ res=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*400,Bid+Point*500,0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } if(OrderType()==1 && OrderStopLoss()>=(Ask+Point*400)){ res=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*400,Ask-Point*500,0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } }else{ if(OrderType()==0){ res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderStopLoss()+Point*2000,0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } if(OrderType()==1 ){ res=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderStopLoss()-Point*2000,0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } if(OrderProfit()>=150){ if(OrderType()==0&& OrderStopLoss()>=(Bid-Point*1000)){ res=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*1000,OrderStopLoss()+Point*3000,0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } if(OrderType()==1 && OrderStopLoss()>=(Ask+Point*1000)){ res=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*1000,OrderStopLoss()-Point*3000,0,Red); if(!res){ Print("Error in OrderModify. Error code=",GetLastError()); }else{ Print("Order modified successfully."); } } } } } } for (n=historyTotal-1;n>historyTotal-2;n--){ if (OrderSelect(n,SELECT_BY_POS,MODE_HISTORY)==false) continue; LastTradeTimeOut = OrderCloseTime(); //Print(LastTradeTimeOut,"最后一单", OrderCloseTime()); //Print( TimeMinute(LastTradeTimeOut),"-",TimeMinute(CurrentTime)); } /* for(j=0; j<historyTotal;j++){ if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)&&(OrderMagicNumber()==Magic)){ if((OrderType()==OP_BUY) || (OrderType()==OP_SELL)) { StrategyProfit+=OrderProfit(); } } } */ //下降趋势 if(total<6 &&CurrentTime-LastTradeTimeOut>3600*24&&nowMa<nowBmPrice&&preMa>preBmPriceOne && TimeHour(LastTradeTimeOut)!=TimeHour(CurrentTime)){ ticket=OrderSend(Symbol(),OP_SELL,0.1,NormalizeDouble(Bid,Digits),1,NormalizeDouble(Bid,Digits)+500*Point,NormalizeDouble(Bid,Digits)-500*Point,"策略二下单",Magic,0,Blue); if(ticket<=0){ Print("策略二错误:",GetLastError()); }else{ Print(ticket,"差值",b,"高峰下降阶段空单"); //Print(Ask,"---","差价:", a,"---",nowBmPrice); Print(rsiNum,"---","RSI参数BUY","---",volumNum,"成交量","-",TimeMinute(LastTradeTimeOut),"-",TimeMinute(CurrentTime)); OrderSelect(ticket,SELECT_BY_TICKET); OrderPrint(); } } //上升趋势 if(total<6 &&CurrentTime-LastTradeTimeOut>3600*24&&nowMa>nowBmPrice&&preMa<preBmPriceOne && TimeHour(LastTradeTimeOut)!=TimeHour(CurrentTime)){ ticket=OrderSend(Symbol(),OP_BUY,0.1,NormalizeDouble(Ask,Digits),1,NormalizeDouble(Ask,Digits)-500*Point,NormalizeDouble(Ask,Digits)+500*Point,"策略一下单",Magic,0,Red); if(ticket<=0){ Print("策略一错误:",GetLastError()); }else{ Print(ticket,"差值",a,"高峰上升阶段多单"); Print(rsiNum,"---","RSI参数BUY","---",volumNum,"成交量","-",TimeMinute(LastTradeTimeOut),"-",TimeMinute(CurrentTime)); OrderSelect(ticket,SELECT_BY_TICKET); OrderPrint(); } } return(0); }