//+------------------------------------------------------------------+
//
// Bookkeeper: Стрелочник на основе индикатора:
//+------------------------------------------------------------------+
//|                                         Waddah_Attar_Def_RSI.mq4 |
//|                              Copyright © 2007, Eng. Waddah Attar |
//|                                          waddahattar@hotmail.com |
//+------------------------------------------------------------------+
//mod cci
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Magenta
//----
extern int CCIPeriod1=14;
extern int CCIPeriod2=34;
extern int smzPeriod =7;
//extern int smzPeriod2=7;
extern int smzMAmode =0;

double   up_buffer1[];
double   dn_buffer1[];
double   ind_buffer1[];
double   ind_buffer2[];
double   MABuffer1[];

//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(0,233); 
   SetIndexArrow(1,234); 
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(0, up_buffer1);
   SetIndexBuffer(1, dn_buffer1);
   SetIndexBuffer(2, ind_buffer1);
   SetIndexBuffer(3, ind_buffer2);
   SetIndexBuffer(4, MABuffer1);

   //SetIndexBuffer(7, MABuffer2);
//----   
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   double rsi1, rsi2;

   int  limit, i, counted_bars = IndicatorCounted();
//----
   if(counted_bars < 0) 
       return(-1);
//----
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
//----
   for(i = limit; i >= 0; i--)
   {
     rsi1 = iCCI(NULL, 0, CCIPeriod1, PRICE_CLOSE, i);
     rsi2 = iCCI(NULL, 0, CCIPeriod2, PRICE_CLOSE, i);
     MABuffer1[i] = (rsi1-rsi2);
   }

//   for(i = 0; i <= limit; i++)   
//     ind_buffer2[i] = iMAOnArray(MABuffer1,0,smzPeriod1,0,smzMAmode,i);

//+------------------------------------------------------------------+
//   for(i=0;i<=limit;i++) ind_buffer1[i] =MABuffer1[i]-ind_buffer2[i];
   for(i=0;i<=limit;i++) ind_buffer2[i] = iMAOnArray(MABuffer1,0,smzPeriod,0,smzMAmode,i);
   for(i=0;i<=limit;i++)
   {
     if(ind_buffer2[i]>0 && ind_buffer2[i+1]<=0)
     {
        dn_buffer1[i]=0;
        up_buffer1[i]=Low[i];
     }
     else
     {
        if(ind_buffer2[i]<0 && ind_buffer2[i+1]>=0)
        {
           up_buffer1[i]=0;
           dn_buffer1[i]=High[i];
        }
        else
        {
           up_buffer1[i]=0;
           dn_buffer1[i]=0;
        }
     }
   }
//+------------------------------------------------------------------+
   
   return(0);
}
//+------------------------------------------------------------------+


