
#property copyright "Copyright © 2007, Aaragorn"

// bug warning...there is a glitch in the display lines which only seems to respond to 
// having all the line thicknesses preset and not compiling the indicator after it is attached.
// if compiled after attaching to chart the line widths go screwy and will not follow the code.
// my suggestion is to keep all line width settings as they are preset and not compile after attaching.
// Reattach as needed to reset line widths.

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green //up
#property indicator_width1 1  
#property indicator_color2 Red  //down 
#property indicator_width2 2 
#property indicator_color3 Blue //line

extern int    StochPeriod1=14;
extern int    DPeriod1=3;
extern int    SlowingPeriod1=3;

double up[], down[], line[];
//+------------------------------------------------------------------+
int init() 
{
   IndicatorBuffers(3);

   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,indicator_width1,indicator_color1);
   SetIndexBuffer(0,up);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,indicator_width1,indicator_color2);
   SetIndexBuffer(1,down);
   SetIndexEmptyValue(1,EMPTY_VALUE);

   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,indicator_width2,indicator_color3);
   SetIndexBuffer(2,line);
   return(0);
}
//+------------------------------------------------------------------+
int deinit() 
{  
}
//+------------------------------------------------------------------+
int start() 
{
 /*   ObjectDelete("Cmmt");
  ObjectCreate("Cmmt", OBJ_TEXT, 0, Time[5], Ask+(-19*Point));
  ObjectSetText("Cmmt","value = "+(iStochastic(Symbol(),0,StochPeriod1,DPeriod1,SlowingPeriod1,MODE_SMA,0,MODE_SIGNAL,0)-50),12,"Arial",Black);   
  ObjectSet("Cmmt", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1);
        
 ObjectDelete("Cmmt1");
  ObjectCreate("Cmmt1", OBJ_TEXT, 0, Time[5], Ask+(-1*Point));
  ObjectSetText("Cmmt1","value 1 = "+(iStochastic(Symbol(),0,StochPeriod1,DPeriod1,SlowingPeriod1,MODE_SMA,0,MODE_SIGNAL,1)-50),12,"Arial",Black);   
  ObjectSet("Cmmt1", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1);  
*/   
   int counted_bars=IndicatorCounted();
   int shift,limit;
   
   IndicatorShortName("Stoch Histogram ("+StochPeriod1+","+DPeriod1+","+SlowingPeriod1+")");
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
  
   limit=Bars-31;
   if(counted_bars>=31) limit=Bars-counted_bars-1;
    
   for (shift=limit;shift>=0;shift--)   
   {
   line[shift]=iStochastic(NULL,0,StochPeriod1,DPeriod1,SlowingPeriod1,MODE_SMA,0,MODE_MAIN,shift)-50;      
   if(line[shift]>0) {up[shift]=line[shift];}
   else if (line[shift]<0)  {down[shift]=line[shift];}  
   }    
   return(0);
}
//+------------------------------------------------------------------+

