//+------------------------------------------------------------------+
//|                                                       MA CCI.mq4 |
//|                                               Copyright © 2009,  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DarkGreen
#property indicator_color2 Lime
#property indicator_color3 Maroon
#property indicator_color4 Red
//#property indicator_color5 Yellow


//---- input parameters
extern int       maPeriod=10;
extern int       maMethod=MODE_SMA;
extern int       maPrice=PRICE_CLOSE;
extern int       cciPeriod=79;
extern int       cciLevel=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//double ExtMapBuffer5[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(3,ExtMapBuffer4);
 //SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,3);
 //SetIndexBuffer(4,ExtMapBuffer5);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int limit;
   int counted_bars=IndicatorCounted();
//---- 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;
//---- main loop
   for(int i=0; i<limit; i++)
     {
         double ma = iMA(NULL,0,maPeriod, 0, maMethod, maPrice, i);
         double cci= iCCI(NULL, 0, cciPeriod, PRICE_TYPICAL, i);
         if (cci >= cciLevel && cci <= 100)
            ExtMapBuffer1[i] = ma;
         else if (cci >100)
            ExtMapBuffer2[i] = ma;
         
         else if  (cci <= cciLevel&& cci >=-100)
            ExtMapBuffer3[i] = ma;
         else if (cci <-100)
            ExtMapBuffer4[i] = ma;
                  
     }
   return(0);
  }
//+------------------------------------------------------------------+