//+------------------------------------------------------------------+
//|                                                MA CCI RSI v5.mq4 |
//|                                               Copyright © 2009,  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright kinonen © 2009"
#property link      ""
// modif kinonen° 2/2009
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 DodgerBlue
#property indicator_color3 Red
#property indicator_color4 Magenta
#property indicator_color5 Blue


//---- input parameters
extern int       maPeriod=20;
extern int       maMethod=MODE_SMA;
extern int       maPrice=PRICE_CLOSE;
extern int       cciPeriod=34;
extern int       rsiPeriod=8;
extern double    cciLevel=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,0);
   SetIndexBuffer(4,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(0,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);
         double rsi= iRSI(NULL, 0,  rsiPeriod, maPrice, i);
         if (cci >= cciLevel && cci <= 100 && rsi>55)  //DodgerBlue
            ExtMapBuffer1[i] = ma;
         else if (cci >=100 && rsi>=55)//Blue
            ExtMapBuffer2[i] = ma;
         else if  (cci <= cciLevel && cci >=-100&& rsi<=45)//Red
            ExtMapBuffer3[i] = ma;
         else if (cci <=-100&& rsi<=45)//Magenta
            {ExtMapBuffer4[i] = ma;}
            
            ExtMapBuffer5[i] = ma;  //   Yellow       
        
     }
   return(0);
  }
//+------------------------------------------------------------------+