//+------------------------------------------------------------------+
//|                             Auslanco QQE_EA.mq4                  |
//|                             Copyright GodfreyH 2008              |
//|                             godfreyh@gmail.com                   |
//|                Multiple Filter if/else Logic modified by Jeffro  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, GodfreyH."
#property link      "godfreyh@gmail.com"

//End-User Changes May Be Made In The Area

extern string EA ="Adjust The Following According To Your System.";

//Money Management

extern string EA1="------------Profit/Loss Controls.------------";
extern double TakeProfit = 120;
extern double StopLoss = 50;
extern double TrailingStop = 110;
extern bool   Show_Settings  = true;
extern string MoMan = "------------Money Management Settings.------------";
extern bool   UseMoneyMgmt= true;
extern bool   RiskPercent1 = false;
extern bool   PercentageBasedLotSize = true;
extern double RiskPercent = 0.1;
extern double LotPercentage = 0.1;
extern bool   MicroOrdersAllowed = false;
extern bool   MiniOrdersAllowed = true;
extern string bb= "---------------------------------------";
extern string cc= "------------Manual Lot Size------------";
extern bool   Manual_Lot_Size = false;
extern double Lotsize = 0.1;
extern string Spread= "Max Spread Allowed";
extern int    SpreadLimit= 10;
extern string Deviation="Max Deviation Allowed";
extern int    Slippage= 7;

//Filters Settings

extern string Filters="Change The Following Variables To Fit Your System";
extern string dd ="------------Filters Control------------";

//Gann HiLo Filter

extern string ee="Filter A";
extern string Gann = "Gann HiLo Settings";
extern bool   GannHiLo1 = true;
extern double Lb= 10;
extern string htf1="Enter TF In Minutes";
extern int    lGannTF = 60;
extern bool   HigherTFGann= true;
extern string htf="Enter Higher TF In Minutes";
extern int    HigherTF = 240;
extern int    LookBack1 = 10;

//QQE Filter

extern string ff="Filter B";
extern string QQE= "QQE Settings";
extern bool   QQECheck1= true;
extern int    SignalTF=60;
extern int    SF = 5;
extern double BuyAbove = 50;
extern double SellBelow = 50;
extern double OverBrought = 70;
extern double OverSold = 30;
extern int    RSIPeriod = 14;
extern double DARFACTOR = 4.236;
extern string gg="Higher TimeFrame QQE";
extern bool   CheckForQQE_LONG_ENTRY= true;
extern int    HigherQQETF= 240;
extern int    Sf1 = 5;

//Momentum Filter

extern string ii="Filter C";
extern string Momentum="Momentum Filter";
extern bool   MomFilter = false;
extern int    MomPeriod = 10;
extern int    MomAppliedPrice = 0;
extern int    MomTF = 1440;

//CCI Filter

extern string  FILTER_E    = "Filter D";
extern bool    CheckForCCI = false;
extern string  CCI ="CCI module";
extern double  CCIPeriod = 30;
extern int     CCIBuyConfirmLevel =  100;
extern int     CCISellConfirmLevel = -100;

//Daily Pivot Filter

extern string jj="Filter E";
extern string PivotFilter="Daily Pivot";
extern bool   CheckForPIVOT = false;

//Moving Average Filter

extern string kk="Filter F";
extern string ll="Moving Average";
extern bool   CheckForMA = true;
extern int    MA_PERIOD = 50;
extern int    MA_Method = 1;
extern int    MA_TF = 60;
extern string mm="Extra Moving Average";
extern bool   Extra_MA = false;
extern int    Ex_MA_Period = 100;
extern int    Ex_MA_Method = 1;
extern int    Ex_MA_TF = 60;

//Bar Length Filter

extern string nn = "Filter G";
extern string Bar_Length ="Bar Length Filter (High - Low)";
extern string Optimizing ="To Allow Length Self-Optimizing (Still Under Test)";
extern bool   SelfOptimizingLength = false;
extern double Deviation_Quotient = 1.5;
extern bool   CheckForStaticLength = false;
extern int    MaxBarLength = 130;
extern int    BarTF = 60;

//Seasons Filter (in attempt to filter traps)

extern string oo= "Filter H";
extern string Hours="Allow Trades In Specified Seasons (In Server Time)";
extern bool   UseHourTrade = false;
extern int    FromHourTrade = 0;
extern int    ToHourTrade = 23;

extern string pp="Divergence Filter (Still Under Test)";
extern bool   DivCheck = true;

extern string qq="Advanced Divergence Filter";
extern bool  AdvDivCheck = true;
extern int   DivPeriod = 14;
extern int   Applied1 = 5;

int MagicNumber          = 12345;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

int init()
  {
    MagicNumber    = subGenerateMagicNumber( MagicNumber, Symbol(), Period() );


 if (Show_Settings)
       PrintDetails();
  
   watermark();
     
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

int deinit()
  {
   return(0);
  }
  
//Expert Functions

bool lGann_HiLo_Check(int cmd) //check if price is below/above Gann HiLo
{
   double lgann = iCustom(Symbol(),lGannTF,"###Gann_HiLo_Activator_v2###",Lb,0,1);
   switch(cmd)
   {
      case OP_BUY  : if(iClose(Symbol(),lGannTF,1) > lgann) return(true);
         break;
      case OP_SELL : if(iClose(Symbol(),lGannTF,1) < lgann) return(true);
   }
   return(false);
}

bool hGann_HiLo_Check(int cmd) //check if higher timeframe price is below/above Gann HiLo
{
   double hgann = iCustom(Symbol(),HigherTF,"###Gann_HiLo_Activator_v2###",LookBack1,0,1);
   switch(cmd)
   {
      case OP_BUY  : if(iClose(Symbol(),HigherTF,1) > hgann) return(true);
         break;
      case OP_SELL : if(iClose(Symbol(),HigherTF,1) < hgann) return(true);
   }
   return(false);
}

bool QQE_Check(int cmd) //check for QQE
{
   double Solid1 = iCustom(Symbol(),SignalTF,"QQEA",SF,RSIPeriod,DARFACTOR,0,2);
   double Solid2 = iCustom(Symbol(),SignalTF,"QQEA",SF,RSIPeriod,DARFACTOR,0,1);
   double Dotted1 = iCustom(Symbol(),SignalTF,"QQEA",SF,RSIPeriod,DARFACTOR,1,2);
   double Dotted2 = iCustom(Symbol(),SignalTF,"QQEA",SF,RSIPeriod,DARFACTOR,1,1);
   
   switch(cmd)
   {
      case OP_BUY  : if((Solid1 < Dotted1) && (Solid2 > Dotted2) && (Solid2 >= BuyAbove) && ((Ask - Bid) <= SpreadLimit) && (Solid2 < OverBrought)) return(true);
         break;
      case OP_SELL : if((Solid1 > Dotted1) && (Solid2 < Dotted2) && (Solid2 <= SellBelow) && ((Ask - Bid) <= SpreadLimit) && (Solid2 > OverSold)) return(true);
   }
   return(false);
}

bool CheckQQE_LONG_ENTRY(int cmd) //check for higher timeframe QQE
{
   double Solidh = iCustom(Symbol(),HigherQQETF,"QQEA",Sf1,RSIPeriod,DARFACTOR,0,1);
   double Dottedh = iCustom(Symbol(),HigherQQETF,"QQEA",Sf1,RSIPeriod,DARFACTOR,1,1);
   
   switch(cmd)
   {
      case OP_BUY  : if(Solidh > Dottedh) return(true);
         break;
      case OP_SELL : if(Solidh < Dottedh) return(true);
   }
   return(false);
}

bool Momentum_Check(int cmd) //check if momentum for a specified timeframe is pointing up or down
{
   double Momentum1 = iMomentum(Symbol(),MomTF,MomPeriod,MomAppliedPrice,1);
   double Momentum2 = iMomentum(Symbol(),MomTF,MomPeriod,MomAppliedPrice,0);
   
   switch(cmd)
   {
      case OP_BUY  : if(Momentum1 <= Momentum2) return(true);
         break;
      case OP_SELL : if(Momentum1 >= Momentum2) return(true);
   }
   return(false);
}

bool CheckCCI(int cmd) //check if cci is above/below a certain level
{

  // CCI VARIABLES


  double CCI_Confirm = iCCI(Symbol(),0,CCIPeriod, PRICE_TYPICAL, 1);
  
  switch (cmd)
  {
   case OP_BUY : if (CCI_Confirm > CCIBuyConfirmLevel) return(true);
             break;     
   case OP_SELL : if (CCI_Confirm < CCISellConfirmLevel) return(true);
  }
  
   
   return(false);
   
   
}

bool CheckPIVOT(int cmd) //if price is above/below pivot
{
   double PrevClose = iClose(Symbol(),PERIOD_D1,1);
   double PrevHigh  = iHigh(Symbol(),PERIOD_D1,1);
   double PrevLow   = iLow(Symbol(),PERIOD_D1,1);
   double Pivot = (PrevHigh + PrevLow + PrevClose)/3;
   double Price = iClose(Symbol(),60,1);
   
   switch (cmd)
   {
      case OP_BUY : if (Price > Pivot ) return(true);
         break;    
      case OP_SELL : if (Price < Pivot) return(true);
   }
   return(false);
}

bool CheckMA(int cmd) //moving average
{
   double MA1 = iMA(Symbol(),MA_TF,MA_PERIOD,0,MA_Method,0,1);
   
   switch(cmd)
   {
      case OP_BUY  : if(iClose(Symbol(),MA_TF,1) > MA1) return(true);
         break;
      case OP_SELL : if(iClose(Symbol(),MA_TF,1) < MA1) return(true);
   }
   return(false);
}

bool eAverage_Check(int cmd) //moving average
{
   double MA2 = iMA(Symbol(),Ex_MA_TF,Ex_MA_Period,0,Ex_MA_Method,0,1);
   
   switch(cmd)
   {
      case OP_BUY  : if(iClose(Symbol(),Ex_MA_TF,1) > MA2) return(true);
         break;
      case OP_SELL : if(iClose(Symbol(),Ex_MA_TF,1) < MA2) return(true);
   }
   return(false);
}

bool CheckBar() //check for bar length
{
   static bool Check = true;
   int cnt;
   double BarsA[48], average, sum = 0;
   if(SelfOptimizingLength) {
      if(Check || (TimeLocal() == 00:00)) {
         for(cnt = 0; cnt < 48; cnt++) {
            BarsA[cnt] = (iHigh(Symbol(),BarTF,cnt+1) - iLow(Symbol(),BarTF,cnt+1));
         }
         for(cnt = 0; cnt < 48; cnt++) {
            sum = sum + BarsA[cnt];
         }
         average = sum/48;
         Check = false;
         Print("The Average Bar Length Is: ", average);
         if((iHigh(Symbol(),BarTF,1) - iLow(Symbol(),BarTF,1)) <= (Deviation_Quotient*average))
            return(true);
      }
    }
    else {
      if(CheckForStaticLength) {
         if((iHigh(Symbol(),BarTF,1) - iLow(Symbol(),BarTF,1)) <= (MaxBarLength*MarketInfo(Symbol(), MODE_POINT)))
            return(true);
      }
    }
    return(false);
}

bool Check_Time() //check for trading hours.
{
   int Hour1 = TimeHour(TimeLocal());
   if ((Hour1 >= FromHourTrade) && (Hour1 <= ToHourTrade)) return(true);
   return(false);
}

bool Div_Check(int cmd) //due to depending on lagging indicator to take a trade, such a method is needed.
{
   double current = iCCI(Symbol(),60,14,5,0);
   double prev = iCCI(Symbol(),60,14,5,2);
   
   switch(cmd)
   {
      case OP_BUY  : if(current > prev) return(true);
         break;
      case OP_SELL : if(current < prev) return(true);
   }
   return(false);
}

bool Advanced_Div_Check(int cmd) //beta method
{
   int counter;
   int shift = 0;
   int shift1 = 0;
   if(cmd == OP_BUY) {
      for(counter = 5;counter <= 77; counter++) { //scan the last 53 bar and get the last peak
         if((iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter+1))
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter+2)) 
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter+3)) 
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter+4))
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter+5))
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter-1)) 
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter-2)) 
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter-3)) 
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter-4))
          && (iHigh(Symbol(),SignalTF,counter) > iHigh(Symbol(),SignalTF,counter-5))) { //check if its a high
           shift = counter; //Latest Major High.
           break;
         }
      }
      if(shift != 0) {
         if((iHigh(Symbol(),SignalTF,1) > iHigh(Symbol(),SignalTF,shift)) && (iCCI(Symbol(),SignalTF,DivPeriod,Applied1,1) < iCCI(Symbol(),SignalTF,DivPeriod,Applied1,shift)))
            return(false);
         if((iHigh(Symbol(),SignalTF,1) < iHigh(Symbol(),SignalTF,shift)) && (iCCI(Symbol(),SignalTF,DivPeriod,Applied1,1) > iCCI(Symbol(),SignalTF,DivPeriod,Applied1,shift)))
            return(false);
      }
   }
   
   if(cmd == OP_SELL) {
      for(counter = 5;counter <= 77; counter++) { //Get the last bottom
         if((iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter+1))
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter+2)) 
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter+3)) 
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter+4))
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter+5)) 
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter-1)) 
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter-2)) 
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter-3)) 
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter-4))
          && (iLow(Symbol(),SignalTF,counter) < iLow(Symbol(),SignalTF,counter-5))) { //check if its a low
            shift = counter; //Last low.
            break;
         }
      }
      if(shift != 0) {
         if((iLow(Symbol(),SignalTF,1) < iLow(Symbol(),SignalTF,shift)) && (iCCI(Symbol(),SignalTF,DivPeriod,Applied1,1) > iCCI(Symbol(),SignalTF,DivPeriod,Applied1,shift)))
            return(false);
         if((iLow(Symbol(),SignalTF,1) > iLow(Symbol(),SignalTF,shift)) && (iCCI(Symbol(),SignalTF,DivPeriod,Applied1,1) < iCCI(Symbol(),SignalTF,DivPeriod,Applied1,shift)))
            return(false);
      }
   }
   return(true);
}

// (Jeffro) Changed conditional structure to be a little more readable and allow for easy addition of future conditions.  
//          If any condition returns false, then CheckEntryCondition will return false.  If all are true, function returns true

bool CheckEntryCondition(int cmd)
{
   if(GannHiLo1)
      if(!lGann_HiLo_Check(cmd))
         return(false);

   if(HigherTFGann)
      if(!hGann_HiLo_Check(cmd))
         return(false);

   if(QQECheck1)
      if(!QQE_Check(cmd))
         return(false);

   if(CheckForQQE_LONG_ENTRY)
      if(!CheckQQE_LONG_ENTRY(cmd))
         return(false);

   if(MomFilter)
      if(!Momentum_Check(cmd))
         return(false);
    
   if(CheckForCCI)
      if(!CheckCCI(cmd))
         return(false);
  
   if(CheckForPIVOT)
      if(!CheckPIVOT(cmd))
         return(false);

   if(CheckForMA)
      if(!CheckMA(cmd))
         return(false);
   
   if(Extra_MA)
      if(!eAverage_Check(cmd))
         return(false);
      
   if(CheckForStaticLength || SelfOptimizingLength)
      if(!CheckBar())
         return(false);
   
   if(UseHourTrade)
      if(!Check_Time())
         return(false);

   if(DivCheck)
      if(!Div_Check(cmd))
         return(false);
   
   if(AdvDivCheck)      
      if(!Advanced_Div_Check(cmd)) return(false);

   return(true); //if we've come this far, everything above has resulted in TRUE, so CheckEntryCondition is TRUE
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
{
   double Lots; 
	int cnt, total, ticket; 
	if (Bars < 100) 
	{ 
		Print("bars less than 100"); 
		return(0); 
	} 
	
	if (TakeProfit < 10) 
	{ 
		Print("TakeProfit less than 10"); 
		return(0); // check TakeProfit 
	} 
   
   int OrdersizeAllowed = 0;
  
   if (MiniOrdersAllowed) OrdersizeAllowed=1;
      
   if (MicroOrdersAllowed) OrdersizeAllowed=2;
   
   if (UseMoneyMgmt) {
      if(RiskPercent1) {
         Lots = NormalizeDouble( AccountBalance()*RiskPercent/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),OrdersizeAllowed);
         PercentageBasedLotSize = false;
      }
      if(PercentageBasedLotSize) {
         Lots = NormalizeDouble(AccountBalance()*(LotPercentage*0.001),OrdersizeAllowed);
      }
      else {
         Manual_Lot_Size = true;
      }
   }
   else {
      Manual_Lot_Size = true;
   }
   
   if (Manual_Lot_Size == true) {
      Lots = NormalizeDouble(Lotsize,OrdersizeAllowed); 
   }   
   if ((Lots < 0.01 && MicroOrdersAllowed) || (Lots < 0.1 && MiniOrdersAllowed && MicroOrdersAllowed == false)) {
         Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");
   }


	total = OrdersTotal(); 
	if (total < 1) { // no opened orders identified 
		if (AccountFreeMargin() < (1000*Lots)) { 
			Print("We have no money. Free Margin = ", AccountFreeMargin()); 
			return(0); 
		} 
   
      if(CheckEntryCondition(OP_BUY)) { // check for long position (BUY) possibility 
	     ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 
						      Bid - StopLoss * Point, Ask + TakeProfit * Point, 
						      "Auslanco", MagicNumber, 0, Green); 
         
         if (ticket > 0) { 
            if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
			      Print("BUY order opened : ", OrderOpenPrice()); 
			   } 
         else 
            Print("Error opening BUY order : ", GetLastError()); 
	   
         return(0); 
      } 
		 
      if(CheckEntryCondition(OP_SELL)) { // check for short position (SELL) possibility 
         ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage,
			   				Ask + StopLoss * Point, Bid - TakeProfit * Point,
				 			   "Auslanco", 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()); 
		
		   return(0); 
	   } 
		
	return(0); 
}

	 
	for (cnt=0; cnt < total; cnt++) 
	{ 
		OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); 
		if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) // // check for opened position & symbol 
		{ 
		
	
		if (OrderType() == OP_BUY) // long position is opened 
			{ 
			 	if (Bid - OrderOpenPrice() > Point*TakeProfit)
			  	{ 
					OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); // close position 
					return(0); // exit 
				} 
				
				
				if (TrailingStop > 0) 
				{ 
					if (Bid - OrderOpenPrice() > Point * TrailingStop) 
					{ 
						if (OrderStopLoss() < Bid-Point * TrailingStop) 
						{ 
							OrderModify(OrderTicket(), OrderOpenPrice(), 
										Bid - Point * TrailingStop, OrderTakeProfit(), 0, Green); 
							return(0); 
						} 
					} 
				} 
			} 
			else 
			{ 
				if (OrderOpenPrice() - Ask > Point*TakeProfit)
				{ 
					OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // close position 
					return(0); // exit 
				} 
				
				if (TrailingStop > 0)
				{ 
					if (OrderOpenPrice() - Ask > Point * TrailingStop) 
					{ 
						if ((OrderStopLoss() > (Ask+Point * TrailingStop)) || (OrderStopLoss() == 0)) 
						{ 
							OrderModify(OrderTicket(), OrderOpenPrice(),
										Ask+Point * TrailingStop, OrderTakeProfit(), 0, Red); 
							return(0); 
						} 
					} 
				} 
			} 
		} 
	} 
	return(0); 
}



void watermark()
  {
   ObjectCreate("Auslanco", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Auslanco","Auslanco EA Trader",12, "Lucida Handwriting", RoyalBlue);
   ObjectSet("Auslanco", OBJPROP_CORNER, 2);
   ObjectSet("Auslanco", OBJPROP_XDISTANCE, 5);
   ObjectSet("Auslanco", OBJPROP_YDISTANCE, 10);
   return(0);
  }

 
void PrintDetails()
{
   string sComment   = "";
   string sp         = "----------------------------------------\n";
   string NL         = "\n";
   //RefreshRates();
   sComment = sp;
   sComment = sComment + "TakeProfit=" + DoubleToStr(TakeProfit,0) + " | ";
   sComment = sComment + "TrailingStop=" + DoubleToStr(TrailingStop,0) + " | ";
   sComment = sComment + "StopLoss=" + DoubleToStr(StopLoss,0) + NL; 
   sComment = sComment + "OrderLots=" +DoubleToStr(OrderLots(),2) +NL;
   sComment = sComment + "If MM used, risk=" +DoubleToStr(RiskPercent,1) + "%" + NL;
   sComment = sComment + sp;
  
   Comment(sComment);
}

//----------------------- GENERATE MAGIC NUMBER BASE ON SYMBOL AND TIME FRAME FUNCTION
//----------------------- SOURCE   : PENGIE
//----------------------- MODIFIED : FIREDAVE
int subGenerateMagicNumber(int MagicNumber, string symbol, int timeFrame)
{
   int isymbol = 0;
   if (symbol == "EURUSD")       isymbol = 1;
   else if (symbol == "GBPUSD")  isymbol = 2;
   else if (symbol == "USDJPY")  isymbol = 3;
   else if (symbol == "USDCHF")  isymbol = 4;
   else if (symbol == "AUDUSD")  isymbol = 5;
   else if (symbol == "USDCAD")  isymbol = 6;
   else if (symbol == "EURGBP")  isymbol = 7;
   else if (symbol == "EURJPY")  isymbol = 8;
   else if (symbol == "EURCHF")  isymbol = 9;
   else if (symbol == "EURAUD")  isymbol = 10;
   else if (symbol == "EURCAD")  isymbol = 11;
   else if (symbol == "GBPUSD")  isymbol = 12;
   else if (symbol == "GBPJPY")  isymbol = 13;
   else if (symbol == "GBPCHF")  isymbol = 14;
   else if (symbol == "GBPAUD")  isymbol = 15;
   else if (symbol == "GBPCAD")  isymbol = 16;
   else                          isymbol = 17;
   if(isymbol<10) MagicNumber = MagicNumber * 10;
   return (StrToInteger(StringConcatenate(MagicNumber, isymbol, timeFrame)));
}