//+------------------------------------------------------------------+
//| MTF Fibo Breakout Alert.mq4
//| author : Giacomo Licciardello (Skyline)
//| email  : glicci@yahoo.it
//+------------------------------------------------------------------+
// v1.0  on 22 May 2007 : Start Project 
// v1.02 on 05 Jun 2007 : e-mail Alert       Christof Risch (iya)
//								  exit signal

#property copyright ""
#property link      ""

#property indicator_chart_window

datetime       lastbar;

extern double  highlimit  = 76.4;
extern double  lowlimit   = 23.6;
extern bool    ExitSignal = false,           // signals crossing of H1 Stoch(14,3,3)
               ExistsSundayCandle = true,
					eMail = true;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators



//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
   Comment ("");
   
//----
   return(0);
}

//+------------------------------------------------------------------+
//| Display alert message and send mail if activated.                |
//+------------------------------------------------------------------+
int ShowAlert(string alert, string text = "")
{
	Alert(alert);

	if(eMail)
		SendMail(alert,text);

//----
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
//----
	string comment;

	if(ExitSignal)	comment = "MTF Fibo Exit Alert ON";
	else				comment = "MTF Fibo Breakout Alert ON";
	if(eMail)		comment = comment+", e-mail ON";

   Comment (comment,
            "\n--------------------------",
            "\nM30 Stoch(5,3,3) = ",DoubleToStr(Stoch(0,30,5),Digits),
            "\nM30 Stoch(14,3,3) = ",DoubleToStr(Stoch(0,30,14),Digits),
            "\n--------------------------",
            "\nH1  Stoch(5,3,3) = ",DoubleToStr(Stoch(0,60,5),Digits),
            "\nH1  Stoch(14,3,3) = ",DoubleToStr(Stoch(0,60,14),Digits));

   datetime curbar = Time[0];
   if (lastbar == curbar)
       return(0);

	lastbar = curbar;

//----
//	Exit
	if (ExitSignal)
	{
		if (Stoch(0,60,14) < highlimit && Stoch(1,60,14) >= highlimit)
			{
          	ShowAlert(Symbol()+" EXIT Signal MTF Fibo Breakout !!",
                      "H1 Stoch(14,3,3) < "+DoubleToStr(highlimit,1)+".");
         }
		if (Stoch(0,60,14) > lowlimit && Stoch(1,60,14) <= lowlimit)
			{
          	ShowAlert(Symbol()+" EXIT Signal MTF Fibo Breakout !!",
                      "H1 Stoch(14,3,3) > "+DoubleToStr(lowlimit,1)+".");
         }
	}
//----
//	Entry
	else
	{
		if (Stoch(0,30,5) >= highlimit && Stoch(0,30,14) >= highlimit && Stoch(0,60,5) >= highlimit && Stoch(0,60,14) >= highlimit &&
			 Bid>YesterdayHigh() )
			{
          	ShowAlert(Symbol()+" BUY Signal MTF Fibo Breakout !!",
                      "M30 and H1 Stoch(5,3,3) and (14,3,3) > "+DoubleToStr(highlimit,1)+" and price broke yesterday's high.");
         }
		if (Stoch(0,30,5) <= lowlimit && Stoch(0,30,14) <= lowlimit && Stoch(0,60,5) <= lowlimit && Stoch(0,60,14) <= lowlimit &&
			 Bid<YesterdayLow() )    
			{
          	ShowAlert(Symbol()+" SELL Signal MTF Fibo Breakout !!",
                      "M30 and H1 Stoch(5,3,3) and (14,3,3) < "+DoubleToStr(lowlimit,1)+" and price broke yesterday's low.");
			}
	}

//----
   return(0);
}

double YesterdayHigh()
{
  if (ExistsSundayCandle==true && DayOfWeek()==1)
   {
    return(iHigh(NULL,PERIOD_D1,2)); 
   }
   else 
   {
    return(iHigh(NULL,PERIOD_D1,1)); 
   }
}
double YesterdayLow()
{
  if (ExistsSundayCandle==true && DayOfWeek()==1)
   {
    return(iLow(NULL,PERIOD_D1,2)); 
   }
   else 
   {
    return(iLow(NULL,PERIOD_D1,1)); 
   }
}

double Stoch(int Shift,int Periodo, int KPeriod)
{
 double Stoch = iStochastic(NULL,Periodo,KPeriod,3,3,MODE_SMA,0,MODE_MAIN,Shift);
 return(Stoch);
}   
//+------------------------------------------------------------------+