//+------------------------------------------------------------------+
//|                                              ChaikinVolty_v1.mq4 |
//|                                  Copyright © 2006, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_separate_window
#property indicator_buffers   1
#property indicator_color1    LightBlue
#property indicator_width1    2
#property indicator_level1    0

//---- input parameters
extern int       HiLoLength   = 10; 
extern int       ROCLength    = 10;
//---- buffers
double CVOL[];
double Range[];
double AvgRange[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CVOL);
   SetIndexBuffer(1,Range);
   SetIndexBuffer(2,AvgRange);
//---- name for DataWindow and indicator subwindow label
   string short_name="Chaikins Volty("+HiLoLength+","+ROCLength+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"RSI");
//----
   SetIndexDrawBegin(0,HiLoLength+ROCLength);
     
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int      shift, limit, counted_bars=IndicatorCounted();
  
//---- 
   if ( counted_bars < 0 ) return(-1);
   if ( counted_bars ==0 ) limit=Bars-1;
   
   if ( counted_bars < 1 ) 
   for(int i=1;i<HiLoLength+ROCLength;i++) 
   {CVOL[Bars-i]=0;Range[Bars-i]=High[Bars-i]-Low[Bars-i];}    
      
   if(counted_bars>0) limit=Bars-counted_bars;
   limit--;
   
   for( shift=limit; shift>=0; shift--)
   Range[shift] = High[shift]-Low[shift];
   
   for( shift=limit; shift>=0; shift--)
   AvgRange[shift] = iMAOnArray(Range,0,HiLoLength,0,MODE_EMA,shift);
         
   for( shift=limit; shift>=0; shift--)
   if(AvgRange[shift+ROCLength]!=0) 
   CVOL[shift] = 100*(AvgRange[shift] - AvgRange[shift+ROCLength])/AvgRange[shift+ROCLength];
   
//----
   return(0);
}
//+------------------------------------------------------------------+