//+------------------------------------------------------------------+
//|                                                   Woodie_CCI.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Blue
#property indicator_color2 Yellow
#property indicator_color3 Yellow
#property indicator_color4 Gray
#property indicator_color5 Green
#property indicator_color6 Red
#property indicator_level1 0
#property indicator_level2 100
#property indicator_level3 -100
#property indicator_level4 200
#property indicator_level5 -200
//---- input parameters
extern int CCIPeriod=14;
extern int TCCIPeriod=6;
//---- indicator buffers
double CCI[];
double TCCI[];
double CCIStart[];
double CCINone[];
double CCIUp[];
double CCIDown[];
int count;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexBuffer(0, CCI);
   SetIndexBuffer(1, TCCI);
   SetIndexBuffer(2, CCIStart);
   SetIndexBuffer(3, CCINone);
   SetIndexBuffer(4, CCIUp);
   SetIndexBuffer(5, CCIDown);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Woodie_CCI");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   double cci_val;
//---- check for possible errors
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=limit-1; i>=0; i--)
     {
      cci_val=iCCI(NULL,0,CCIPeriod,PRICE_TYPICAL,i);
      CCI[i]=cci_val;
      TCCI[i]=iCCI(NULL,0,TCCIPeriod,PRICE_TYPICAL,i);
      if ((CCI[i]>0 && CCI[i+1]>0) || (CCI[i]<0 && CCI[i+1]<0)) count++; else count=0;
      if (count<4) CCINone[i]=cci_val;
      if (count==4) CCIStart[i]=cci_val;
      if (count>4)
      {
      if (cci_val>0) CCIUp[i]=cci_val; else CCIDown[i]=cci_val;
      }
     }

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

