//+------------------------------------------------------------------+
//|                                                  cci squeeze.mq4 |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color5  DimGray
#property indicator_color1  Green
#property indicator_color2  LimeGreen
#property indicator_color3  Orange
#property indicator_color4  Red
#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2
#property indicator_width5  2

//
//
//
//
//

extern int MaLength  = 200;
extern int MaPrice   = PRICE_CLOSE;
extern int MaMethod  = MODE_EMA;
extern int CCILength = 50;
extern int CCIPrice  = PRICE_TYPICAL;

//
//
//
//
//

double cci[];
double cciUpa[];
double cciUpb[];
double cciDna[];
double cciDnb[];

//
//
//
//
//

int    timeFrame;
string indicatorFileName;
bool   returnBars;
bool   calculateValue;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
   SetIndexBuffer(0, cciUpa); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1, cciUpb); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2, cciDna); SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(3, cciDnb); SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(4, cci);
   return(0);
}

int deinit()
{
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
{
   int limit,i,counted_bars = IndicatorCounted();

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
       limit = MathMin(Bars - counted_bars,Bars-1);


   //
   //
   //
   //
   //

   for(i = limit; i >= 0 ; i--)
   {
      double ma    = iMA(NULL,0,MaLength,0,MaMethod,MaPrice,i);
      double price = iMA(NULL,0,1       ,0,MODE_SMA,MaPrice,i);
         cci[i]    = iCCI(NULL,0,CCILength,CCIPrice,i);
         cciUpa[i] = EMPTY_VALUE;
         cciUpb[i] = EMPTY_VALUE;
         cciDna[i] = EMPTY_VALUE;
         cciDnb[i] = EMPTY_VALUE;
         if (cci[i]>0)
         {
            if (price>ma) cciUpa[i] = cci[i];
            if (price<ma) cciUpb[i] = cci[i];
         }
         if (cci[i]<0)
         {
            if (price>ma) cciDna[i] = cci[i];
            if (price<ma) cciDnb[i] = cci[i];
         }
   }
   return(0);
}