
#property indicator_separate_window
#property indicator_buffers 5

#property indicator_color1 Lime
#property indicator_width1  5

#property indicator_color2 Red
#property indicator_width2  5

#property indicator_color3 White
#property indicator_width3  1


#property indicator_color4 clrCornflowerBlue
#property indicator_width4  1

#property indicator_color5 clrCornflowerBlue
#property indicator_width5  1


input int period=1; // Close of a bar how many periods back


double diff[], up[], dn[];
double  up2[], dn2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
    
//---- indicator line
   IndicatorBuffers(5);
   
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,up);
   
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,dn);
   
   SetIndexStyle(2,DRAW_LINE, STYLE_DASH,1);
   SetIndexBuffer(2,diff);  
   
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,up2);
   
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexBuffer(4,dn2);
   
   return(0);
  }

//----


 
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    
    
    int limit = rates_total - prev_calculated;	
    
    if(prev_calculated > 0) {
		limit++;
    }
    for(int i=limit-1; i>=0  && !IsStopped(); i--){   
        
        diff[i] = Close[i]-Open[i]; 
        
        if (diff[i] > 0.0 ){ 
            up[i] = diff[i];
            up2[i] = High[i]-Open[i];
            dn2[i] = Low[i] - Open[i];
        }
        if (diff[i]<0.0){ 
            dn[i]=diff[i]; 
            up2[i] = High[i]-Open[i];
            dn2[i] = Low[i] - Open[i];
        }
    }
    
    return(rates_total);
}
