mql4 H4 10日均线+20日布林带交叉+移动止盈长盈利

未结帖
0 3363
ajian admin_jim 2018-06-10
悬赏:5飞吻
//+------------------------------------------------------------------+
//|                                                     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);
      

 


          
}


热忱回答0


最近热帖

近期热议

  1. javascript——prototype与__proto 9
  2. Mysql 中出现的Data truncated for column 3
  3. 在nginx中使用x-sendfile的解决方案 3
  4. 高版本jQuery面插件实现Ajax上传图片 1
  5. Thinkphp Socket.class.php 类的使用 1
  6. 使用ionic3创建第一个App 0
  7. ios-oc html5 0
  8. nginx.conf 0
  9. 基于ionic3.4.0的项目搭建 0
  10. php 缩略图 0