//+------------------------------------------------------------------+
//|                                                #KinoCCIsF4M.mq4  |
//|                      Copyright © 2008, 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 DarkGreen
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Maroon
#property indicator_color5 DarkKhaki 
#property indicator_color6 Yellow

#property indicator_level1 100
#property indicator_level2 -100
#property indicator_level3 0
#property indicator_level4 300
#property indicator_level5 -300
#property indicator_level6 -50
#property indicator_level7 50


#property indicator_levelcolor White

extern int CCI1=21;
extern int CCI2=89;
extern bool Popup_Alert=false;
extern bool Email_Alert=false;
bool signal=false;
//---- buffers 
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
 //---- indicators

   SetIndexStyle(0,DRAW_HISTOGRAM, EMPTY, 4, DarkGreen);
   SetIndexBuffer(0,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_HISTOGRAM, EMPTY, 4, Lime);
   SetIndexBuffer(1,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_HISTOGRAM, EMPTY, 4, Maroon );
   SetIndexBuffer(2,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_HISTOGRAM, EMPTY, 4, Red);
   SetIndexBuffer(3,ExtMapBuffer5);
   SetIndexStyle(4,DRAW_LINE, EMPTY, 3, DarkKhaki );
   SetIndexBuffer(4,ExtMapBuffer6);
   SetIndexStyle(5,DRAW_LINE, EMPTY, 4, Yellow);
   SetIndexBuffer(5,ExtMapBuffer1);
   
   SetIndexLabel(0,"CCI 0/100");  
   SetIndexLabel(1,"CCI>100+");
   SetIndexLabel(2,"CCI<0 -100");
   SetIndexLabel(3,"CCI< -100");
   SetIndexLabel(5,"CCI1");   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {int limit;
   double val1,val2,val3,val5,val4;
   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 = 1000; i >= 0; i--) 
  { 
  val1=iCCI(NULL,0,CCI1,PRICE_TYPICAL,i);
  val2=iCCI(NULL,0,CCI2,PRICE_TYPICAL,i);
  
  
  ExtMapBuffer1[i]=val1;  //CCI21
  ExtMapBuffer6[i]=val2;
  
  if (val2>=0&& val2<=100)
  ExtMapBuffer2[i]=val2;
  else
  if (val2>=100)
  ExtMapBuffer3[i]=val2;
  else
  if (val2<=0&& val2>=-100)
  ExtMapBuffer4[i]=val2;
  else
  if (val2<=-100)
  ExtMapBuffer5[i]=val2;
  }
//----
   if(ExtMapBuffer1[0]>100 && signal==false )
   {
      if (Popup_Alert){Alert("BUY NOW - CCI21 Value is ",ExtMapBuffer1[0]); signal =true;}
      if (Email_Alert){SendMail("BUY NOW - CCI21 Value is ",ExtMapBuffer1[0]); signal =true;}
      }
   if(ExtMapBuffer1[0]<-100 && signal==false)
   {
      if (Popup_Alert) {Alert("SELL NOW - CCI21 Value is ",ExtMapBuffer1[0]); signal =true;}
      if (Email_Alert) {SendMail("SELL NOW - CCI21 Value is ",ExtMapBuffer1[0]); signal =true;}
   }
   
   if(ExtMapBuffer1[0]<100 && ExtMapBuffer1[0]>-100) signal=false;
    
//----
   return(0);
  }
//+------------------------------------------------------------------+