//+------------------------------------------------------------------+
//|                                     Stochastic Cross Alerter.mq4 |
//|                                    Copyright © 2009, Roy Connell |
//|                                                          http:// |
//+------------------------------------------------------------------+
/*Alerts when stochastic crosses the lower or upper threshold.*/


#property copyright "Copyright © 2009, Roy Connell"
#property link      ""

#property indicator_chart_window

extern int kperiod = 9;
extern int dperiod = 3;
extern int slowing = 3;
extern double UpperThreshold = 80.0; //Upper stochastic value for alert
extern double LowerThreshold = 20.0; //Lower stochastic value for alert
double stoch[2];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
   stoch[0] = iStochastic(NULL, Period(), kperiod, dperiod, slowing, MODE_SMMA, 0, MODE_SIGNAL, 0);
   stoch[1] = iStochastic(NULL, Period(), kperiod, dperiod, slowing, MODE_SMMA, 0, MODE_SIGNAL, 1);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   stoch[0] = iStochastic(NULL, Period(), kperiod, dperiod, slowing, MODE_SMMA, 0, MODE_SIGNAL, 0);
   stoch[1] = iStochastic(NULL, Period(), kperiod, dperiod, slowing, MODE_SMMA, 0, MODE_SIGNAL, 1);
   if ((stoch[0] > UpperThreshold) && (stoch[1] < UpperThreshold)) Alert(Symbol(), " stochastic crossed above ", UpperThreshold, "  Value = ", stoch[0]);
   if ((stoch[0] < UpperThreshold) && (stoch[1] > UpperThreshold)) Alert(Symbol(), " stochastic crossed below ", UpperThreshold, "  Value = ", stoch[0]);  
   if ((stoch[0] < LowerThreshold) && (stoch[1] > LowerThreshold)) Alert(Symbol(), " stochastic crossed below ", LowerThreshold, "  Value = ", stoch[0]);
   if ((stoch[0] > LowerThreshold) && (stoch[1] < LowerThreshold)) Alert(Symbol(), " stochastic crossed above ", LowerThreshold, "  Value = ", stoch[0]);
   return(0);
  }
//+------------------------------------------------------------------+