//+------------------------------------------------------------------+
//|                                                #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 YellowGreen
#property indicator_color3 Red
#property indicator_color4 Maroon
#property indicator_color5 DarkOliveGreen 
#property indicator_color6 Red

#property indicator_level1 100
#property indicator_level2 -100
#property indicator_level3 0






#property indicator_levelcolor White

extern int CCI1=14;
extern int CCI2=55;
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, 2, DarkGreen);
   SetIndexBuffer(0,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_HISTOGRAM, EMPTY, 2, YellowGreen);
   SetIndexBuffer(1,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_HISTOGRAM, EMPTY, 2, Maroon );
   SetIndexBuffer(2,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_HISTOGRAM, EMPTY, 2, Red);
   SetIndexBuffer(3,ExtMapBuffer5);
   SetIndexStyle(4,DRAW_LINE, EMPTY, 2, DarkOliveGreen );
   SetIndexBuffer(4,ExtMapBuffer6);
   SetIndexStyle(5,DRAW_LINE, EMPTY, 2, Red);
   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);
  }
//+------------------------------------------------------------------+