诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

以ATR作为止损水平的网格马丁EA Fluid Blue 3.3.mq4

Fluid Blue 3.3 EA属于网格加码类型的策略,采用ATR作为止损水平。

源码:

//+------------------------------------------------------------------+
//|                                               Fluid Blue 3.3.mq4 |
//|                                                   Matt Pavlovich |
//+------------------------------------------------------------------+
#property copyright "Matt Pavlovich"
#property link      "http://www.125808047.com/"

extern double    MinTime = 120;
extern double    drawdown1 = 10;
extern double    drawdown2 = 20;
extern double    drawdown3 = 30;
extern double    MaxLots = 100;
extern double    stop = 10;//1 - 4hr//
extern double    profit = 30;//3 - 4hr//
extern double    trailer = 0.5;
extern bool      DoubleDown = true;
extern bool      TrippleDown = true;
extern bool      QuadDown = true;
extern bool      Reverse = false;
extern bool      micro = false;
extern bool      mini = false;
extern bool      standard = true;
double           Lots;
int              MagicNumber=333;
extern int       maxsp = 22;
bool             cg = false;
double    riskm = 75;//micro=75, mini=7.5, standard=.75//
double    riskM = 7.5;//micro=75, mini=7.5, standard=.75//
double    riskS = 0.75;//micro=75, mini=7.5, standard=.75//

int OnInit()
{  
Comment("www.125808047.com");
return(INIT_SUCCEEDED);
}
     
void OnTick()
{
   int cnt, ticket, total;
   double SL,TP;
   
   if (Lots>MaxLots) Lots=MaxLots;
   if (Lots>=100)
   Alert("Take your profits and run!!  Your broker will not allow more than 100 lots!  You cannot double down from here!  Stop trading!");
   
   if (micro)
   Lots=(MathCeil(AccountEquity() * riskm / 100000)/100);
   
   if (mini)
   Lots=(MathCeil(AccountEquity() * riskM / 100000)/10);
   
   if (standard)
   Lots=(MathCeil(AccountEquity() * riskS / 100000));

   double TrailingStop,myao;
   TrailingStop = iATR(Symbol(),0,14,1)*trailer;
   myao = iAC(Symbol(),0,0);
   if (!IsTesting()) Comment(" TrailingStop=",DoubleToStr(TrailingStop,4));
   total = 0; 
   for(cnt=OrdersTotal()-1; cnt>=0; cnt--)
     {
      cg = OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
      if ( OrderSymbol()      != Symbol())     continue;
      if ( OrderMagicNumber() != MagicNumber)  continue;
      if(OrderType() == OP_BUY )  total++;
      if(OrderType() == OP_SELL ) total++;
     }
 
     {
      if(OrdersTotal()==0 && Ask-Bid<=maxsp*Point && myao>0)
        {
         SL=Ask-iATR(Symbol(),0,14,0)*stop;
         TP=Ask+iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL,TP,"",MagicNumber,0,Blue);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("BUY order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening BUY order : ",GetLastError()); 
           }
         }
           
      if(OrdersTotal()==0 && Ask-Bid<=maxsp*Point && myao<0)
        {
         SL=Bid+iATR(Symbol(),0,14,0)*stop;
         TP=Bid-iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL,TP,"",MagicNumber,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("SELL order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening SELL order : ",GetLastError());  
           }
         }
      if (DoubleDown)
      if(OrdersTotal()==1 && Ask-Bid<=maxsp*Point && OrderOpenPrice()-Ask>=drawdown1*Point && myao>0)
        {
         SL=Ask-iATR(Symbol(),0,14,0)*stop;
         TP=Ask+iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_BUY,Lots*2,Ask,1,SL,TP,"",MagicNumber,0,Blue);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("BUY order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening BUY order : ",GetLastError()); 
           }
         }
         
      if (DoubleDown)   
      if(OrdersTotal()==1 && Ask-Bid<=maxsp*Point && Bid-OrderOpenPrice()>=drawdown1*Point && myao<0)
        {
         SL=Bid+iATR(Symbol(),0,14,0)*stop;
         TP=Bid-iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_SELL,Lots*2,Bid,1,SL,TP,"",MagicNumber,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("SELL order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening SELL order : ",GetLastError());  
           }
         }
      if (TrippleDown)
      if(OrdersTotal()==2 && Ask-Bid<=maxsp*Point && OrderOpenPrice()-Ask>=drawdown2*Point && myao>0)
        {
         SL=Ask-iATR(Symbol(),0,14,0)*stop;
         TP=Ask+iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_BUY,Lots*4,Ask,1,SL,TP,"",MagicNumber,0,Blue);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("BUY order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening BUY order : ",GetLastError()); 
           }
         }
         
      if (TrippleDown)   
      if(OrdersTotal()==2 && Ask-Bid<=maxsp*Point && Bid-OrderOpenPrice()>=drawdown2*Point && myao<0)
        {
         SL=Bid+iATR(Symbol(),0,14,0)*stop;
         TP=Bid-iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_SELL,Lots*4,Bid,1,SL,TP,"",MagicNumber,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("SELL order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening SELL order : ",GetLastError());  
           }
         }
      if (QuadDown)
      if(OrdersTotal()==3 && Ask-Bid<=maxsp*Point && OrderOpenPrice()-Ask>=drawdown3*Point && myao>0)
        {
         SL=Ask-iATR(Symbol(),0,14,0)*stop;
         TP=Ask+iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_BUY,Lots*8,Ask,1,SL,TP,"",MagicNumber,0,Blue);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("BUY order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening BUY order : ",GetLastError()); 
           }
         }
         
      if (QuadDown)   
      if(OrdersTotal()==3 && Ask-Bid<=maxsp*Point && Bid-OrderOpenPrice()>=drawdown3*Point && myao<0)
        {
         SL=Bid+iATR(Symbol(),0,14,0)*stop;
         TP=Bid-iATR(Symbol(),0,14,0)*profit;
         ticket=OrderSend(Symbol(),OP_SELL,Lots*8,Bid,1,SL,TP,"",MagicNumber,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
              {
               Print("SELL order opened : ",OrderOpenPrice());
              }
           }
         else 
           {
            Print("Error opening SELL order : ",GetLastError());  
           }
         }
     }
       
 for(cnt=total-1; cnt>=0; cnt--)
     {
      cg = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         TrailingStop = iATR(Symbol(),0,14,1)*trailer;
         if (TrailingStop<=0.0005) TrailingStop=0.0006;
         if(OrderType()==OP_BUY)   // long position is opened //
           {
            if ((Bid - OrderOpenPrice() >=4*Point && CurTime()-OrderOpenTime()>=MinTime))
                {
                 RefreshRates();
                 cg = OrderClose(OrderTicket(),OrderLots(),Bid,1,Violet); // close position
               }
            if (Reverse)
            if (myao<0)
                {
                 RefreshRates();
                 cg = OrderClose(OrderTicket(),OrderLots(),Bid,1,Violet); // close position
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-TrailingStop)
                    {
                      RefreshRates();
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop,OrderTakeProfit(),0,Blue);
                    }
                 }
              }
           }

         if(OrderType()==OP_SELL)   // short position is opened //
           {
            if ((OrderOpenPrice()- Ask >=40*Point && CurTime()-OrderOpenTime()>=MinTime))
                {
                 RefreshRates();
                 cg = OrderClose(OrderTicket(),OrderLots(),Ask,1,Violet); // close position
                }
            if (Reverse)
            if (myao>0)
                {
                 RefreshRates();
                 cg = OrderClose(OrderTicket(),OrderLots(),Ask,1,Violet); // close position
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+TrailingStop)) || (OrderStopLoss()==0))
                    {
                      RefreshRates();
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop,OrderTakeProfit(),0,Red);
                    }
                 }
              }
           }
        }
     }
 }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 以ATR作为止损水平的网格马丁EA Fluid Blue 3.3.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏