//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
//mod 
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers    3
#property indicator_color1     DarkOliveGreen
#property indicator_color2     Green
#property indicator_color3     Red

#property indicator_width1     1
#property indicator_width2     2
#property indicator_width3     2

//#property indicator_minimum    -350
//#property indicator_maximum     350
//////
#property indicator_level1     100
#property indicator_level2     -100
#property indicator_levelcolor DarkSlateGray


extern int period      = 14;

extern int price       = 0;
extern bool histo = 1;

double buffer1[];
double buffer2[];
double buffer3[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
if (histo) int draw= DRAW_HISTOGRAM;else draw= DRAW_LINE;

   SetIndexStyle(0,draw);   SetIndexStyle(1,draw);   SetIndexStyle(2,draw);



   
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3);

   IndicatorShortName("cci  " +period);  
   SetIndexLabel(0,"cci");



   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+



int start()
{
   int counted_bars=IndicatorCounted();
   int limit,i;
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit=Bars-counted_bars;


   for(i=limit; i>=0; i--)
   {
                                             buffer2[i]=EMPTY_VALUE;
                                             buffer3[i]=EMPTY_VALUE;
               
               buffer1[i]  = iCCI(NULL, 0, period,  price, i); 
               
      if      (buffer1[i]>buffer1[i+1])      buffer2[i]  = buffer1[i]; 
      else                                   
      if      (buffer1[i]<buffer1[i+1])      buffer3[i]  = buffer1[i]; 
 
 
   
  }
   
   return(0);
}


