Navigation:Home > Content >

BBQ_EA_v1.1.1_EURUSD_M5_Beta.mq4

Time: 2018-12-07 | Download file:BBQ_EA_v1.1.1_EURUSD_M5_Beta.mq4

//+------------------------------------------------------------------+
//|                                               BBQ_EA_V1.1.1 Beta |
//|                                                        M5 EURUSD |
//|                                   created by Monty666 2013-06-20 |
//+------------------------------------------------------------------+
//
#property copyright "Copyright © 2012 Monty666"
#property link      "BBQ_EA_V1.1.1"
#include 
#include  
//
//---- input parameters
extern string mm = "MoneyManagement";
extern double StopLoss     = 33;
extern double TakeProfit   = 120;
extern double Lots = 0.1;
extern bool UseMM = FALSE;
extern double PercentageMM = 10.0;
extern int SlipPage = 1;
extern double MaxSpread = 1.1;
extern int TrailingStop = 4;
extern int TrailingStep = 24;
extern int BreakEven = 3;
extern int movestopto = 2;
extern bool UseStrategy1 = TRUE;
extern bool UseStrategy2 = TRUE;
extern double Distance = 10;
int exp = 2600;
extern string deleteOrders = "delete pending after x minutes";
extern int DelOrders = 10;
extern string Timefilter = "GMT offset broker";
extern int    ServerTimeZone = 0;
extern int    TimeControl  = 0;
extern int    HourStartGMT   = 2;
extern int    HourStopGMT    = 23;
extern string News   = "Newsfilter";
extern bool AvoidNews        = TRUE;
extern int MinimumImpact     = 2;
extern int MinsBeforeNews    = 60;
extern int MinsAfterNews     = 30;
extern string Friday = "FridayFinalHour";
extern bool   UseFridayFinalTradeTime = TRUE;
extern int    FridayFinalHourGMT = 15;
extern string  SignalSettings    = "Signals"; 
extern int MA_Period = 99;
extern int Slippage_MA = 28;
extern int Williams_Period = 21;
extern int Level_High = 5;
extern int Level_Low = 95;
extern int ATR_Period = 18;
extern int Level_ATR_Stop = 4;
extern int CCI_Period = 16;
extern int Level_CCI_High = 90;
extern int Level_CCI_Low = -110;
// macd
extern double MACDOpenLevel = 3;
extern double MACDCloseLevel = 2;
extern double MATrendPeriod = 24;
// sar adx
extern double SAR_Step = 0.012;
extern double SAR_Maximum = 0.2;
extern double ADX_Level=25;
extern double ADX_Period = 14;
extern string Choose_ADX_Price = "0=close, 1=open, 2=high, 3=low, 4=median, 5=typical, 6=weighted";
extern double ADX_Price = 0;
extern string Choose_ADX_Mode = "0=Base indicator line, 1=+DI indicator line, 2=-DI indicator line";
extern double ADX_Mode = 0;
// close
extern string  SignalClose    = "Close settings"; 
extern int Close_Williams = 1;
extern int Williams_Close_Buy = 80;
extern int Williams_Close_Sell = 40;
extern int Only_Profit = 2;
extern int Close_CCI = 0;
extern int CCI_Close_Buy = 20;
extern int CCI_Close_Sell = -70;
// magic
extern int MagicNumber1           = 19777;
extern int MagicNumber2           = 18777;
extern string TradeComment       = "BBQ";

double point;
int digits,i,D;
int BarCount;
int Current;
int bc=-1,tpb,tps,cnt,total;
int gi_240 = 0;
int gi_244 = 0;
int gi_224 = 0;
int gi_228 = 6;
int gi_328;
int g_error_332;
double g_price_336;
double g_price_344;
double g_price_352;
double gd_360;
double gd_368;
double g_iclose_376;
double g_iatr_384;
double g_iwpr_392;
double g_icci_400;
double g_ima_408;
int g_datetime_420;
// pivot
bool AsLongAs=true;int ExtFormula=0;

//+------------------------------------------------------------------+
//| Time Filter                                                      |
//+------------------------------------------------------------------+
bool TradeSession() {
   int Hour_Start_Trade;
   int Hour_Stop_Trade;
   Hour_Start_Trade = HourStartGMT + ServerTimeZone;
   Hour_Stop_Trade = HourStopGMT + ServerTimeZone;
   if (Hour_Start_Trade < 0)Hour_Start_Trade = Hour_Start_Trade + 24;
   if (Hour_Start_Trade >= 24)Hour_Start_Trade = Hour_Start_Trade - 24;
   if (Hour_Stop_Trade > 24)Hour_Stop_Trade = Hour_Stop_Trade - 24;
   if (Hour_Stop_Trade <= 0)Hour_Stop_Trade = Hour_Stop_Trade + 24;
   if ((UseFridayFinalTradeTime && (Hour()>=FridayFinalHourGMT + ServerTimeZone) && DayOfWeek()==5)||DayOfWeek()==0)return (FALSE); // Friday Control
   if((TimeControl(Hour_Start_Trade,Hour_Stop_Trade)!=1 && TimeControl==1 && Hour_Start_TradeHour_Stop_Trade)
          ||TimeControl==0)return (TRUE); // "Trading Time";
    return (FALSE); // "Non-Trading Time";
}

int TimeControl(int StartHour, int EndHour)
{
   if (Hour()>=StartHour &&  Hour()< EndHour)
      { 
      return(0);
      }
return(1);
}

//+------------------------------------------------------------------+
//| Lots Sizes and Automatic Money Management                        |
//+------------------------------------------------------------------+
 double GetLots()
 { 
   if (UseMM)
    {
      double a, maxLot, minLot;
      a = (PercentageMM * AccountFreeMargin() / 100000);
      double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
      maxLot  = MarketInfo(Symbol(), MODE_MAXLOT );
      minLot  = MarketInfo(Symbol(), MODE_MINLOT );   
      a =  MathFloor(a / LotStep) * LotStep;
      if (a > maxLot) return(maxLot);
      else if (a < minLot) return(minLot);
      else return(a);
    }    
   else return(Lots);
 }
 
//+------------------------------------------------------------------+
//| close by signal                                                  |
//+------------------------------------------------------------------+   
bool close_signal(int ai_0, double ad_4) {
   if (ai_0 == 0) {
      if (Close_Williams > 0 && (-1.0 * g_iwpr_392) < Williams_Close_Buy && Only_Profit < 0 || Bid > ad_4 + Only_Profit * gi_328 * Point) return (1);
      if (Close_CCI > 0 && g_icci_400 > CCI_Close_Buy) return (1);
      if (gi_224 > 0 && g_iatr_384 < gi_228 * gi_328 * Point) return (1);
      if (gi_240 == 1 && iClose(NULL, 0, 1) < g_ima_408) return (1);
      if (gi_244 == 1 && g_ima_408 < iMA(NULL, 0, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 2)) return (1);
   }
   if (ai_0 == 1) {
      if (Close_Williams > 0 && (-1.0 * g_iwpr_392) > Williams_Close_Sell && Only_Profit < 0 || Ask < ad_4 - Only_Profit * gi_328 * Point) return (1);
      if (Close_CCI > 0 && g_icci_400 < CCI_Close_Sell) return (1);
      if (gi_224 > 0 && g_iatr_384 < gi_228 * gi_328 * Point) return (1);
      if (gi_240 == 1 && iClose(NULL, 0, 1) > g_ima_408) return (1);
      if (gi_244 == 1 && g_ima_408 > iMA(NULL, 0, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 2)) return (1);
   }
   return (0);
}	 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//Calculate for 4 or 5 digits broker
    if(Digits==5||Digits==3){ D=10;}
    else{D=1;}
    if(Digits<4)
   {
      point=0.01;
      digits=2;
      gi_328 = 10;
   }
   else
   {
      point=0.0001;
      digits=4;
      gi_328 = 1;
   }

   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| MaxSpread                                                        |
//+------------------------------------------------------------------+
bool Mspread() {
   double Spread = Ask-Bid;
   if(Spread <= MaxSpread * point)return (TRUE);
    return (FALSE);
}  

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int cnt, ticket, ticket2, ticket3, ticket4, total;
  double SL,TP; 
  total=OrdersTotal();
  int OpenedOrders=0;

//+------------------------------------------------------------------+
//| newsfilter                                                       |
//+------------------------------------------------------------------+
	bool ContinueTrading=true;
   if(AvoidNews && !IsTesting())
   {
   static int PrevMinute=-1;  
   
   int MinSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,0);
   int MinToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,1);
         
   int ImpactSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,0);
   int ImpactToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,1);

   if(Minute()!=PrevMinute)
   {
   PrevMinute=Minute();
   if((MinToNews<=MinsBeforeNews &&  ImpactToNews>=MinimumImpact) || (MinSinceNews<=MinsAfterNews && ImpactSinceNews>=MinimumImpact))ContinueTrading=false;
   }
	}
	
//+------------------------------------------------------------------+
//| trailing                                                         |
//+------------------------------------------------------------------+
	createlstoploss(StopLoss);
	createltakeprofit(TakeProfit);
	createsstoploss(StopLoss);
	createstakeprofit(TakeProfit);	

	if(TrailingStop>0)MoveTrailingStop();
	if(BreakEven>0)MoveBreakEven();	
//+------------------------------------------------------------------+
//| signals                                                          |
//+------------------------------------------------------------------+  
	int sign1, sign2, sign3, sign4, sign5, sign6, sign0;

// wsfr signals

	g_iclose_376 = iClose(NULL, 0, 1);
	g_ima_408 = iMA(NULL, 0, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 1);
	g_iwpr_392 = iWPR(NULL, 0, Williams_Period, 1);
	g_iatr_384 = iATR(NULL, 0, ATR_Period, 1);
	g_icci_400 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, 1);
	g_datetime_420 = iTime(Symbol(), 0, 0);
// buy	
	if (g_iclose_376 > g_ima_408 + Slippage_MA * gi_328 * point && g_iwpr_392 < (-1 * Level_Low) && g_icci_400 < Level_CCI_Low && g_iatr_384 > Level_ATR_Stop * gi_328 * point) sign1=1;	
// sell
	if (g_iclose_376 < g_ima_408 - Slippage_MA * gi_328 * point && g_iwpr_392 > (-1 * Level_High) && g_icci_400 > Level_CCI_High && g_iatr_384 > Level_ATR_Stop * gi_328 * point) sign1=-1;


// Pivot
   int limit=1;
   for(int i=1;i<=limit;i++)
   {
 
	double DPa=iCustom(Symbol(),0,"DailyPivot_Shift",ServerTimeZone,ExtFormula,0,i);
	double DP=iCustom(Symbol(),0,"DailyPivot_Shift",ServerTimeZone,ExtFormula,0,0);
      
	string BUY="false";
	string SELL="false";

	if((AsLongAs==false&&Open[i]DP)||(AsLongAs==true&&Open[0]>DP))BUY="true";
	if((AsLongAs==false&&Open[i]>DPa&&Open[0]SignalCurrent && MacdPrevious(MACDOpenLevel*point) && MaCurrent>MaPrevious) sign4=1;
	if(MacdCurrent>0 && MacdCurrentSignalPrevious && MacdCurrent>(MACDOpenLevel*point) && MaCurrentADX_Level) sign5=1;
   if (SARCurrent>Ask && ADX>ADX_Level) sign5=-1;

// conditions
	string Buy1="false";
	string Sell1="false";
	string Buy2="false";
	string Sell2="false";

	string Buy1Check="true";
	string Sell1Check="true";
	string Buy2Check="true";
	string Sell2Check="true";

   if (sign1==1 && sign2==1)
      { 
      Buy1="true";
      Buy2Check="false";
      }
   if (sign1==-1 && sign2==-1)
      { 
      Sell1="true";
      Sell2Check="false";
      }
      
//+------------------------------------------------------------------+
//| count open orders                                                |
//+------------------------------------------------------------------+

	int totalo;
	totalo=0;
	
	for(int io=0;ioMinutes_2delete*60 ||!ContinueTrading) && OrderType()==OP_BUYSTOP)
         {     
         OrderDelete(OrderTicket());
         }
         else
         if((TimeCurrent()-OrderOpenTime()>Minutes_2delete*60 ||!ContinueTrading) && OrderType()==OP_SELLSTOP)
         {     
         OrderDelete( OrderTicket() );  
         }
      }
   }   	
//+------------------------------------------------------------------+
//| open orders                                                      |
//+------------------------------------------------------------------+
//
	double MyAsk = Ask + Distance*point;
	double MyBid = Bid - Distance*point;
	
// wsfr indis standardorder ////////////////////////
// buyorder
	if (UseStrategy1 && TradeSession() && ContinueTrading && Mspread() && totalo<1 && Buy1=="true")
	{
	ticket=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,SlipPage,0,0,TradeComment,MagicNumber1,0,Green);	if(ticket<0)
	{
	Print("OrderSend failed with error #",GetLastError());
	return(0);
	}
	}
// Sellorder
	if (UseStrategy1 && TradeSession() && ContinueTrading && Mspread() && totalo<1 && Sell1=="true")
	{
	ticket=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,SlipPage,0,0,TradeComment,MagicNumber1,0,Red);	if(ticket<0)
	{
	Print("OrderSend failed with error #",GetLastError());
	return(0);
	}
	}		


// macd stoporder ////////////////////////
// buy stoporder
	if (UseStrategy2 && sign4==1 && sign2==1 && sign5==1 && totalp<1 && totalo<1 && TradeSession() && ContinueTrading && Mspread())
	{
	ticket3 = OrderSend(Symbol(), OP_BUYSTOP, GetLots(), MyAsk, SlipPage, 0, 0, TradeComment, MagicNumber2, expire, Lime);
	Sleep(1000);
	RefreshRates();
	if(ticket3<0)
	{
	Print("OrderSend failed with error #",GetLastError());
	return(0);
	}
	}

// Sell stoporder
	if (UseStrategy2 && sign4==-1 && sign2==-1 && sign5==-1 && totalp<1 && totalo<1 && TradeSession() && ContinueTrading && Mspread())	
	{
	ticket3 = OrderSend(Symbol(), OP_SELLSTOP, GetLots(), MyBid, SlipPage, 0, 0, TradeComment, MagicNumber2, expire, Orange);
	Sleep(1000);
	RefreshRates();
	if(ticket3<0)
	{
	Print("OrderSend failed with error #",GetLastError());
	return(0);
	}
	}
//+------------------------------------------------------------------+
//| open orders end                                                  |
//+------------------------------------------------------------------+
   return(0);
  }


//+------------------------------------------------------------------+
//| trailing functions 1                                             |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
   int cnt,total=OrdersTotal();
for(cnt=0; cnt0&&NormalizeDouble(Ask-TrailingStep*point,digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*point,digits))  
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)0&&NormalizeDouble(Bid+TrailingStep*point,digits)(NormalizeDouble(Ask+TrailingStop*point,digits)))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*point,digits),OrderTakeProfit(),0,Red);
               }
            }
         }
      }
   }
}
return(0);
}

//+------------------------------------------------------------------+
//| breakeven 1                                                      |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
   int cnt,total=OrdersTotal();
for(cnt=0; cnt0)
            {
               if(NormalizeDouble((Bid-OrderOpenPrice()),digits)>BreakEven*point)
               {
                  if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),digits)<0)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+movestopto*point,digits),OrderTakeProfit(),0,Blue);
                  }
               }
            }
         }
         else
         {
            if(BreakEven>0)
            {
               if(NormalizeDouble((OrderOpenPrice()-Ask),digits)>BreakEven*point)
               {
                  if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),digits)<0)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-movestopto*point,digits),OrderTakeProfit(),0,Red);
                  }
               }
            }
         }
      }
   }
   
   }

   return(0);
}


// add TP & SL

void createlstoploss(double StopLoss){
   RefreshRates();
   for(int i=0;i        

Recommend