#property copyright ""

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue 
#property indicator_width1 2  
#property indicator_color2 Red 
#property indicator_width2 2  
#property indicator_color3 DarkGreen 
#property indicator_width3 2  
#property indicator_color4 CLR_NONE 

#property indicator_level2 110
#property indicator_level3 -10
#property indicator_level4 80
#property indicator_level5 20
#property indicator_level6 50
#property indicator_levelcolor Black
#property indicator_levelstyle 2
#property indicator_levelwidth 1

extern int    StochPeriod1 = 8, DPeriod1 = 3, SlowingPeriod1 = 3;
extern int    MA_Method=0; // SMA 0, EMA 1, SMMA 2, LWMA 3
extern int    PriceField=0; // Low/High 0, Close/Close 1

double upB[], loB[], Stoch1[], Stoch2[];

//+------------------------------------------------------------------+
int init() {

   IndicatorBuffers(4);
   
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0, upB);
   SetIndexArrow(0,251);
   //SetIndexEmptyValue(0, EMPTY_VALUE);
   
   
   SetIndexStyle(1, DRAW_ARROW); 
   SetIndexBuffer(1, loB);
   SetIndexArrow(0,159);
   //SetIndexEmptyValue(1, EMPTY_VALUE);
   

   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, Stoch1);
   
   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, Stoch2);
   IndicatorShortName("");
   SetIndexLabel(0, "");
   SetIndexLabel(1, "");
   SetIndexLabel(2, "");
   SetIndexLabel(3, "");
   
   IndicatorShortName("Stochastic_Dot_Line");
   return(0);
}

//+------------------------------------------------------------------+
int deinit()
 {
   
   
 }
 
//+------------------------------------------------------------------+
int start() {

   int counted_bars = IndicatorCounted();
   int shift, limit;
   
   if (counted_bars <0) return(-1);
   if (counted_bars >0) counted_bars--;
  
   limit = Bars-1;
   if(counted_bars >= 1) limit = Bars - counted_bars -1;

   for (shift = limit; shift >= 0; shift--) 
     {
      Stoch1[shift] = iStochastic(NULL,0,StochPeriod1,DPeriod1,SlowingPeriod1,MA_Method,PriceField,MODE_MAIN,shift);      
      Stoch2[shift] = iStochastic(NULL,0,StochPeriod1,DPeriod1,SlowingPeriod1,MA_Method,PriceField,MODE_SIGNAL,shift);      

      if(Stoch1[shift] > Stoch2[shift])
       {
         upB[shift] = Stoch1[shift];
         loB[shift] = 0;
       } 
      else if (Stoch1[shift] < Stoch2[shift])
       {
         loB[shift] = Stoch1[shift];
         upB[shift] = 0;
       }
     }
   
   return(0);

}
//+------------------------------------------------------------------+

