//+------------------------------------------------------------------+
//|                                      Marts 4Hour Stoch Alert.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

// Indicator modified 19.9.07,  to alert only on stochs falling below 80% ,and rising above 20% . 

#define INDICATOR_NAME		"Marts 4Hour stoch alert "
#define INDICATOR_VERSION	"v1.1"


#property indicator_chart_window


extern int    Sto_period = 14;   // Set to 5 or 14 as prefered

   //Screen Alerts
extern int    Sto_4 = 240;
extern bool   Sto_Alert = true;  // will give an alert when 4 Hour Crosses > 20 and rising or < 80 and falling.
extern int    Max_sto_Alerts=1;
   //Email Alerts
extern int    EMail_4 = 240;
extern bool   EMail_Alert= true;
extern int    Max_Alerts=1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
     ObjectDelete("Marts_4H_Stoch_Sto_4");
       
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   string  Sto_4_stoch_char;
   int    counted_bars=IndicatorCounted();
     
  
   
   
    
   
   double Sto_4_main   = iStochastic(NULL,Sto_4,Sto_period,3,3,MODE_SMA,0,MODE_MAIN,0);
   double Sto_4_signal   = iStochastic(NULL,Sto_4,Sto_period,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   
   // These alerts are given for stoch levels coming out of oversold Between 20-23.6%, and overbought below 80-76.4%,
   
   //Long Screen Alerts
   {{
   if ( Sto_Alert == true && Sto_4_main > Sto_4_signal && ( Sto_4_signal > 20)&&(Sto_4_signal < 23.6))
   if (NewBar())
   Alert (Symbol()," "," 4 Hour Stoch more than 20% **BUY** ");
   }
   {
   //Long email alert
   if (EMail_Alert == true && Sto_4_main > Sto_4_signal && ( Sto_4_signal > 20)&&(Sto_4_signal < 23.6))
   
   if(Max_Alerts==0)
		return(0);
	
	if(EMail_Alert)
		SendMail("Stoch 4Hour Alert","20% **BUY**");
	
   return(0);
   }}
   
   
   
   //Short Screen Alerts
   {{
   if ( Sto_Alert == true && Sto_4_main < Sto_4_signal && ( Sto_4_signal < 80)&&(Sto_4_signal > 76.4))
   if (NewBar())
   Alert (Symbol()," "," 4 Hour Stoch less than 80% **SELL** ");
   }
   {
   //Short email alert
   if (EMail_Alert == true && Sto_4_main < Sto_4_signal && ( Sto_4_signal < 80)&&(Sto_4_signal > 76.4))
   
   if(Max_Alerts==0)
		return(0);
	
	if(EMail_Alert)
		SendMail("Stoch 4Hour Alert","80% **SELL**");
	
   return(0);
   }}
   
}
 bool NewBar()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0]; Sleep(100); // wait for tick
return(true);
}
return(false);
}   
   
   
   
   
   
//----
   
//----
   return(0);
  
//+------------------------------------------------------------------+


