
#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() 
{
   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;
   
  ObjectDelete("Cmmt");
  ObjectCreate("Cmmt", OBJ_TEXT, 0, Time[15], Ask+(30*Point));
  ObjectSetText("Cmmt","shift = "+shift,12,"Arial",Black);   
  ObjectSet("Cmmt", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
        
  ObjectDelete("Cmmt1");
  ObjectCreate("Cmmt1", OBJ_TEXT, 0, Time[15], Ask+(50*Point));
  ObjectSetText("Cmmt1","limit = "+limit,12,"Arial",Black);   
  ObjectSet("Cmmt1", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);


   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];   
      } 
  ObjectDelete("Cmmt2");
  ObjectCreate("Cmmt2", OBJ_TEXT, 0, Time[15], Ask+(70*Point));
  ObjectSetText("Cmmt2","counted_bars = "+counted_bars,12,"Arial",Black);   
  ObjectSet("Cmmt2", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
        
  ObjectDelete("Cmmt12");
  ObjectCreate("Cmmt12", OBJ_TEXT, 0, Time[15], Ask+(90*Point));
  ObjectSetText("Cmmt12","limit = "+limit,12,"Arial",Black);   
  ObjectSet("Cmmt12", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);    
        
   } 
  ObjectDelete("Cmmt9");
  ObjectCreate("Cmmt9", OBJ_TEXT, 0, Time[15], Ask+(110*Point));
  ObjectSetText("Cmmt9","line[0] = "+line[0],12,"Arial",Black);   
  ObjectSet("Cmmt9", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
        
/*  ObjectDelete("Cmmt1");
  ObjectCreate("Cmmt1", OBJ_TEXT, 0, Time[15], Ask+(-20*Point));
  ObjectSetText("Cmmt1","line[1] = "+line[1],12,"Arial",Black);   
  ObjectSet("Cmmt1", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
  
  ObjectDelete("Cmmt2");
  ObjectCreate("Cmmt2", OBJ_TEXT, 0, Time[15], Ask+(-30*Point));
  ObjectSetText("Cmmt2","line[2] = "+line[2],12,"Arial",Black);   
  ObjectSet("Cmmt2", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
  
  ObjectDelete("Cmmt3");
  ObjectCreate("Cmmt3", OBJ_TEXT, 0, Time[15], Ask+(-40*Point));
  ObjectSetText("Cmmt3","line[3] = "+line[3],12,"Arial",Black);   
  ObjectSet("Cmmt3", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);

  ObjectDelete("Cmmt4");
  ObjectCreate("Cmmt4", OBJ_TEXT, 0, Time[15], Ask+(-50*Point));
  ObjectSetText("Cmmt4","line[4] = "+line[4],12,"Arial",Black);   
  ObjectSet("Cmmt4", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
        
  ObjectDelete("Cmmt5");
  ObjectCreate("Cmmt5", OBJ_TEXT, 0, Time[15], Ask+(-60*Point));
  ObjectSetText("Cmmt5","line[5] = "+line[5],12,"Arial",Black);   
  ObjectSet("Cmmt5", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
  
  ObjectDelete("Cmmt6");
  ObjectCreate("Cmmt6", OBJ_TEXT, 0, Time[15], Ask+(-70*Point));
  ObjectSetText("Cmmt6","line[6] = "+line[6],12,"Arial",Black);   
  ObjectSet("Cmmt6", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
  
  ObjectDelete("Cmmt7");
  ObjectCreate("Cmmt7", OBJ_TEXT, 0, Time[15], Ask+(-80*Point));
  ObjectSetText("Cmmt7","line[35] = "+line[35],12,"Arial",Black);   
  ObjectSet("Cmmt7", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
*/
/*  ObjectDelete("Cmmt");
  ObjectDelete("Cmmt1");
  ObjectDelete("Cmmt2");
  ObjectDelete("Cmmt3");
  ObjectDelete("Cmmt4");
  ObjectDelete("Cmmt5");
  ObjectDelete("Cmmt6");
  ObjectDelete("Cmmt7");  
*/  
    
   return(0);
}
//+------------------------------------------------------------------+

