//+------------------------------------------------------------------+
//|                                              #CCIs&RSI8___v5.mq4  |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                     http://kinonen.over-blog.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://kinonen.over-blog.com"


#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 OrangeRed
#property indicator_color2 Lime
#property indicator_color3 DarkGreen
#property indicator_color4 LawnGreen
#property indicator_color5 Red
#property indicator_color6 Orange
#property indicator_color7 Blue
#property indicator_color8 DodgerBlue

#property indicator_width1     2
#property indicator_width2     2
#property indicator_width3     2
#property indicator_width4     2
#property indicator_width5     2
#property indicator_width6     2
#property indicator_width7     2
#property indicator_width8     2


#property indicator_level1  300
#property indicator_level2  200
#property indicator_level3  100
#property indicator_level4 -100
#property indicator_level5 -200
#property indicator_level6 -300


#property indicator_levelcolor Teal


extern int CCI1=34;
extern int CCI2=170;
extern int RSI=8;
extern int RSIdeflectLv=5;
extern int RsiMultiplicator=3;

extern int NbOfCandles=1500;

//---- buffers 
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];

int rsiuplv, rsidnlv;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
 //---- indicators
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 159); //234
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle (1, DRAW_ARROW);
   SetIndexArrow (1, 159); //233
   SetIndexBuffer(1,ExtMapBuffer2); 
   
   SetIndexStyle (2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle (3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle (4,DRAW_HISTOGRAM);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle (5,DRAW_HISTOGRAM);
   SetIndexBuffer(5,ExtMapBuffer6);


   SetIndexStyle (6,DRAW_LINE);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexStyle (7,DRAW_LINE);
   SetIndexBuffer(7,ExtMapBuffer8);

   for(int b=0;b<=indicator_buffers;b++)    SetIndexEmptyValue (b,EMPTY_VALUE);

   SetIndexLabel(0,"cci1 cci2 rsi Up");
   SetIndexLabel(1,"cci1 cci2 rsi Dn");  

   
   rsiuplv=50+RSIdeflectLv;  
   rsidnlv=50-RSIdeflectLv;
   
   SetIndexLabel(2,"RSI "+RSI+">"+rsiuplv+"");
   SetIndexLabel(3,"50<RSI<"+rsiuplv+"");
   SetIndexLabel(4,"RSI "+RSI+"<"+rsidnlv+"");
   SetIndexLabel(5,""+rsidnlv+"<RSI<50");
   
   SetIndexLabel(6,"CCI "+CCI1+"");
   SetIndexLabel(7,"CCI "+CCI2+"");  

   string shortname = " CCI "+CCI1+", CCI "+CCI2+", RSI "+RSI+",";
   
   IndicatorShortName(shortname +" kino ");  
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {int limit;
   double val1,val2,val3,val22,val11,val33;
   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;
   limit = MathMin(limit,NbOfCandles);
   
   //==========================================
   for(int i = limit; i >= 0; i--) 
   { 
   val1=iCCI(NULL,0,CCI1,PRICE_TYPICAL,i);
   val11=iCCI(NULL,0,CCI1,PRICE_TYPICAL,i+1);
   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);
   val33=iRSI(NULL,0,8,PRICE_CLOSE,i+1);
  
  
   if ((val2>0 && val1>0 && val11<0)||(val1>0 && val2>0 && val22<0)&& (val3>rsiuplv) )  //&& val3>55)
               ExtMapBuffer2[i]=-100;
   else  
   if ((val2<0 && val1<0 && val11>0)||(val1<0 && val2<0 && val22>0) && (val3<rsidnlv)) // && val33>45 )
               ExtMapBuffer1[i]= 100;
   
   else  {     ExtMapBuffer2[i]=EMPTY_VALUE; ExtMapBuffer1[i]=EMPTY_VALUE;
         }
  
  
  
  
   ExtMapBuffer3[i]=0.0; ExtMapBuffer4[i]=0.0; ExtMapBuffer5[i]=0.0; ExtMapBuffer6[i]=0.0;
   
   double   val3m=(val3-50)*RsiMultiplicator;
  
   if (val3>50)     {   if (val3>rsiuplv)  ExtMapBuffer3[i]=val3m;   
                        else               ExtMapBuffer4[i]=val3m;   
                    }
   else              {  if (val3<rsidnlv)  ExtMapBuffer5[i]=val3m;   
                        else               ExtMapBuffer6[i]=val3m;  
                     } 

    
  ExtMapBuffer7[i]=val1;  //CCI34
  ExtMapBuffer8[i]=val2;  //CCI170
  
    
  }

   
//----
   return(0);
  }
//+------------------------------------------------------------------+