//+------------------------------------------------------------------+
//|                                                   Histoch V1.mq4 |
//|                               Copyright (C) July, 2008, by LaurV |
//|                                                       vamist.com |
//+------------------------------------------------------------------+
#property copyright "Copyright (C) July, 2008, by LaurV"
#property link      "vamist.com"

#property indicator_separate_window
#property indicator_buffers 2

//---- indicator buffers
double     ind_buffer0[];
double     ind_buffer1[];

//all parameters below set to MT4 defaults of Stochastic indicator, 
//feel free to change them to your needs 

extern int K_Period     =  5;    //%K - see Stochastic() default parameters
extern int D_Period     =  3;    //%D - see Stochastic() default parameters
extern int Slowing      =  3;    //MA - see Stochastic() default parameters

extern int MA_Method    =  0;    //Can be one of this values: 
                                 // 0 - Simple moving average, 
                                 // 1 - Exponential moving average, 
                                 // 2 - Smoothed moving average, 
                                 // 3 - Linear weighted moving average 
                                 //See iStochastic() parameters

extern int Price_Field  =  0;    //Can be one of this values: 
                                 // 0 - Low/High
                                 // 1 - Close/Close
                                 //See iStochastic() parameters

extern color ColorUp = Green;    //obvious... :P
extern color ColorDn = Red;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{  SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,ColorUp);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,ColorDn);
   SetIndexBuffer(0,ind_buffer0);
   SetIndexBuffer(1,ind_buffer1);
   IndicatorShortName("Histoch("+K_Period+","+D_Period+","+Slowing+")");
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{  
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();

  //---- check for possible errors
     if(counted_bars<0) return(-1);

  //---- the last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;

  //---- main loop
     for(int i=0; i<limit; i++)
       {  //---- singurele linii adaugate de mine in program :P
          //---- ... calculeaza diferenta dintre cele doua linii ale lui stoch
         double x=iStochastic(Symbol(),0,K_Period,D_Period,Slowing,MA_Method,Price_Field,MODE_MAIN,i)-
                  iStochastic(Symbol(),0,K_Period,D_Period,Slowing,MA_Method,Price_Field,MODE_SIGNAL,i);
         
         if (x>=0) 
            ind_buffer0[i]=x;
         else
            ind_buffer1[i]=x;   
         
       }

  //---- done

   return(0);
  }
//+------------------------------------------------------------------+