//+------------------------------------------------------------------+
//|                                                          CCI.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Orange
//---- input parameters
extern int CCIPeriod = 14;

extern color GridColor = DimGray;

//---- buffers
double CCIBuffer[];
double RelBuffer[];
double DevBuffer[];
double MovBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
 

//---- indicator lines
   SetIndexStyle(0, DRAW_HISTOGRAM,0,2);
   SetIndexBuffer(0, CCIBuffer);
//----
   if(CCIPeriod <= 0)
       CCIPeriod = 14;
//----
   SetIndexDrawBegin(0, CCIPeriod);
  
//---- name for DataWindow and indicator subwindow label
   short_name="CCI(" + CCIPeriod + ")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
   
   

   SetLevelStyle(STYLE_DOT, 1, GridColor) ;
   SetLevelValue(1,300 );
   SetLevelValue(2,200 );   
   SetLevelValue(3,100 );
   SetLevelValue(4,0);
   SetLevelValue(5,-100 );
   SetLevelValue(6,-200 );
   SetLevelValue(7,-300 );    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Commodity Channel Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i, k, counted_bars = IndicatorCounted();
 
   if(CCIPeriod <= 1)
       return(0);
       
   if(Bars <= CCIPeriod) 
       return(0);
       
//---- initial zero
   if(counted_bars < 1)
     {
       for(i = 1; i <= CCIPeriod; i++) 
           CCIBuffer[Bars-i] = 0.0;
     }
     
//---- last counted bar will be recounted
   int limit = Bars - counted_bars;
   if(counted_bars > 0)  limit++;
 
   for(i = 0; i < limit; i++)
   {
       CCIBuffer[i] = iCCI(NULL,0,CCIPeriod,0,i) ;
   }
 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+