//+------------------------------------------------------------------+
//|                                                  #CCIs&RSI8.mq4  |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                     http://kinonen.over-blog.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://kinonen.over-blog.com"


#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Aqua
#property indicator_color2 Lime
#property indicator_color3 Yellow
#property indicator_color4 Orange
#property indicator_color5 Green
#property indicator_color6 Red


extern int CCI1=34;
extern int CCI2=170;
extern int RsiMultiplicator=1;
extern int NbOfCandles=1000;

//---- buffers 
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
 //---- indicators
   SetIndexStyle(0,DRAW_LINE, EMPTY, 3, Aqua);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE, EMPTY, 3, Blue);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, EMPTY, 4, Lime);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, EMPTY, 4, Crimson );
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(4,DRAW_HISTOGRAM, EMPTY, 4, Yellow);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(5,DRAW_HISTOGRAM, EMPTY, 1, Red);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexLabel(0,"CCI 34");
   SetIndexLabel(1,"CCI 170");  
   SetIndexLabel(2,"RSI>55");
   SetIndexLabel(3,"RSI<45");
   SetIndexLabel(4,"45<RSI<55");
      
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {int limit;
   double val1,val2,val3,val5,val4,val22;
   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;
   //==========================================
   for(int i = NbOfCandles; i >= 0; i--) 
  { 
  val1=iCCI(NULL,0,CCI1,PRICE_TYPICAL,i);
  val2=iCCI(NULL,0,CCI2,PRICE_TYPICAL,i);
  val22=iCCI(NULL,0,CCI2,PRICE_TYPICAL,i+1);
  
  val3=iRSI(NULL,0,8,PRICE_CLOSE,i);
  
  if(val2>0 && val2<0 && val1<0)
   ExtMapBuffer6[i]=200;
  else  
  if(val2<0 && val2>0 && val1>0)
   ExtMapBuffer6[i]=-200;
  else 
  
  ExtMapBuffer1[i]=val1;  //CCI34
  ExtMapBuffer2[i]=val2;  //CCI170
    
  if (val3>=55)
  ExtMapBuffer3[i]=val3*RsiMultiplicator;
  else
  if (val3<=45)
  ExtMapBuffer4[i]=-val3*RsiMultiplicator;
  else
  ExtMapBuffer5[i]=-val3*RsiMultiplicator;
  
  
    
  }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+