//+------------------------------------------------------------------+
//| SpudFyre Stochs.mq4
//| Rob Rice (blueruby)
//| http://www.forexfactory.com/showthread.php?t=13321&highlight=boxingislife
//+------------------------------------------------------------------+

#property copyright "Rob Rice (blueruby)"
#property link      "http://www.forexfactory.com/showthread.php?t=22105"

#property indicator_chart_window

datetime       lastbar;
bool           EmailSent;

extern bool    EmailAlert;
extern bool    SoundON;
extern double  highlimit = 80;
extern double  lowlimit = 20;


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

   Comment ("SpudFyre signal indicator ON");

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
   Comment ("");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   
   double main_15 = iStochastic(NULL,PERIOD_M15,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   double signal_15 = iStochastic(NULL,PERIOD_M15,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   double main_30 = iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   double signal_30 = iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   double main_1H = iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   double signal_1H = iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   double main_4H = iStochastic(NULL,PERIOD_H4,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   double signal_4H = iStochastic(NULL,PERIOD_H4,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);


   datetime curbar = Time[0];
   if (lastbar != curbar)
      {
      lastbar = curbar;
      if ((main_15 < lowlimit) && (main_30 < lowlimit) && (main_1H < lowlimit) && (main_4H < lowlimit))
      if ((signal_15 < lowlimit) && (signal_30 < lowlimit) && (signal_1H < lowlimit) && (signal_4H < lowlimit))
         {
         Alert ("SpudFyre short early warning ",Symbol()," ",Period()," min");
         if (EmailAlert && !EmailSent) 
            {
            SendMail("SpudFyre","Short early warning on " + (StringConcatenate(Symbol()," ",Period())));
            EmailSent = true;
            }
         if (SoundON == true) PlaySound ("alert2.wav");
         }
      
      if ((main_15 > highlimit) && (main_30 > highlimit) && (main_1H > highlimit) && (main_4H > highlimit))
      if ((signal_15 > highlimit) && (signal_30 > highlimit) && (signal_1H > highlimit) && (signal_4H > highlimit))
         {
         Alert ("SpudFyre long early warning on ",Symbol()," ",Period()," min");
         if (EmailAlert && !EmailSent) 
            {
            SendMail("SpudFyre","Long early warning on " + (StringConcatenate(Symbol()," ",Period())));
            EmailSent = true;
            }
         if (SoundON == true) PlaySound ("alert2.wav");
         }  
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+