//+------------------------------------------------------------------+
//|                                            Stoch Overlay.mq4     |
//|                      Copyright © 2007, Joshua Jones            . |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, Joshua Jones"
#property  link      "http://www.forexfactory.com/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_level1 76.4
#property  indicator_level2 61.8
#property  indicator_level3 50.0
#property  indicator_level4 38.2
#property  indicator_level5 23.6
#property  indicator_levelcolor DarkGray
#property  indicator_levelstyle STYLE_DOT
//---- indicator parameters
extern int Mins = 0;

extern int stoch1_K = 5;
extern int stoch1_D = 3;
extern int stoch1_slowing = 3;
extern int stoch2_K = 14;
extern int stoch2_D = 3;
extern int stoch2_slowing = 3;

//---- indicator buffers
double     stoch1[];
double     stoch2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if (Mins == 0)
      Mins = Period();

   string stoch1name = "Stoch (" + stoch1_K + "," + stoch1_D + "," + stoch1_slowing + ")";
   string stoch2name = "Stoch (" + stoch2_K + "," + stoch2_D + "," + stoch2_slowing + ")";
   SetIndexBuffer(0,stoch1);
   SetIndexLabel(0,stoch1name);
   SetIndexBuffer(1,stoch2);
   SetIndexLabel(1,stoch2name);
   
   string tf;
   
   if (Mins < PERIOD_H1)
      tf = Mins + " Minute";
   else if (Mins == PERIOD_H1 || Mins == PERIOD_H4)
      tf = Mins/60 + " Hour";
   else if (Mins == PERIOD_D1)
      tf = "1 Day";
   else if (Mins == PERIOD_W1)
      tf = "1 Week";
   else if (Mins == PERIOD_MN1)
      tf = "1 Month";
   
   
   IndicatorShortName(tf + " " +  stoch1name + " and " + stoch2name);
  
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()   
   {
//---- drawing settings
   
   int limit;  
   int counted_bars=IndicatorCounted(); 
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   
   limit=Bars-counted_bars;
   

   double mult = 1;
   
   if (Period() > Mins)
      mult = Period() / Mins;
   // TODO


   double stoch1val = 0;
   double stoch2val = 0;
   for(int i=0; i< limit; i++)
   {
      for (int j = 0; j < mult; j++)
      {
         stoch1val += iStochastic(NULL,Mins,stoch1_K,stoch1_D,stoch1_slowing,MODE_SMA,0,MODE_MAIN,(i*mult)+j);
         stoch2val += iStochastic(NULL,Mins,stoch2_K,stoch2_D,stoch2_slowing,MODE_SMA,0,MODE_MAIN,(i*mult)+j);
      }
         stoch1[i] = stoch1val/mult;
         stoch2[i] = stoch2val/mult;
         
         stoch1val = 0;
         stoch2val = 0;
   }

   return(0);
  }