//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#property  copyright ""
#property  link      ""

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Magenta
#property indicator_color3 Lime
#property indicator_width1 2
#property indicator_width2 4
#property indicator_width3 4
#property indicator_maximum 1
#property indicator_minimum 0

//
//
//
//
//

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//double ma[];

//
//
//
//
//

extern int    K_Period  = 5;
extern int    D_Period  = 3;
extern int    Slowing  = 3;
extern int    TopBorder=60;
extern int    BotBorder=40;

extern string TypeMA    = "SMA=0, EMA=1, SMMA=2, LWMA=3";
extern int    MAType    =  0;
//extern int    MAShift   =  0;
extern string TypePrice = "0 - Low/High, 1 - Close/Close";
extern int    PriceType =  0;

//
//
//
//
//

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
   IndicatorBuffers(4);
      SetIndexBuffer(0,ExtMapBuffer1);
      SetIndexBuffer(1,ExtMapBuffer2);
      SetIndexBuffer(2,ExtMapBuffer3);
 //     SetIndexBuffer(3,ma);
      SetIndexStyle(0,DRAW_HISTOGRAM);
      SetIndexStyle(1,DRAW_HISTOGRAM);
      SetIndexStyle(2,DRAW_HISTOGRAM);
   return(0);
}

//
//
//
//
//

int start()
{ 
   int      counted_bars=IndicatorCounted();
   int      limit,i;


   if(counted_bars < 0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;

   //
   //
   //
   //
   //
   
//   for(i = limit; i >= 0; i--) ma[i]=iMA(NULL,0,MAPeriod,MAShift,MAType,PriceType,i);
   for(i = limit; i >= 0; i--)
   {  
      double St=iStochastic(NULL,0,K_Period,D_Period,Slowing,MAType,PriceType,MODE_MAIN,i);
      ExtMapBuffer1[i] = EMPTY_VALUE;
      ExtMapBuffer2[i] = EMPTY_VALUE;
      ExtMapBuffer3[i] = EMPTY_VALUE;
         if (St>BotBorder && St<TopBorder) ExtMapBuffer1[i] = 1;
         if (St<BotBorder) ExtMapBuffer2[i] = 1;
         if (St>TopBorder) ExtMapBuffer3[i] = 1;
   }
   return(0);
}