//+------------------------------------------------------------------+
//|                                            #CCIcolouredbyRSI.mq4 |
//|                                              written by kaza007. |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 DimGray
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_level1  0

//---- input parameters
extern int CCIPeriod=14;
extern int RSIPeriod=8;
extern int RSILongTrigger=50;
extern int RSIShortTrigger=50;
string TrigStr;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
   IndicatorShortName("CCI/RSI ("+"CCI:"+CCIPeriod+", RSI:"+RSIPeriod+", LongTrig:"+RSILongTrigger+", ShortTrig:"+RSIShortTrigger+")");
   //TrigStr = "(LongTrig:"+RSILongTrigger+", ShortTrig:"+RSIShortTrigger+")";
   TrigStr = "---";
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars = IndicatorCounted();
   int    limit        = Bars - counted_bars;
   for (int i = 0; i < limit; i++ )
   {
//----
      double RSIval = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
      if (RSIval>RSILongTrigger) 
      {
         ExtMapBuffer1[i]=iCCI(NULL,0,CCIPeriod,PRICE_CLOSE,i);
      }else if (RSIval<RSIShortTrigger) 
      {
         ExtMapBuffer2[i]=iCCI(NULL,0,CCIPeriod,PRICE_CLOSE,i);
      }else
      {
         ExtMapBuffer3[i]=iCCI(NULL,0,CCIPeriod,PRICE_CLOSE,i);
      }
//----
   }
   return(0);
  }
//+------------------------------------------------------------------+