//+------------------------------------------------------------------+
//|                                               extrem bars colored|
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Maroon
#property indicator_color3 Green
#property indicator_color4 Maroon
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2



//
//
//
//
//
extern string NameInd    = "VQZL"; //имя индикатора стрелочника
extern int BuffBuy       = 0; 
extern int BuffSell      = 1;
int    PriceSmoothing       = 15;
int    PriceSmoothingMethod = MODE_LWMA;  
extern double Filter               = 5;
//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   SetIndexBuffer(0,buffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_HISTOGRAM);

   return(0);
}

//
//
//
//
//

int deinit()
{
   return(0);
}

//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;
   
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
           limit = Bars-counted_bars;
 
   //
   //
   //
   //
   //
            
   for (i=limit; i>=0; i--)
   {  
      double IndBuy=iCustom(Symbol(),0,NameInd,PriceSmoothing,PriceSmoothingMethod,Filter,BuffBuy,i);
      double IndSell=iCustom(Symbol(),0,NameInd,PriceSmoothing,PriceSmoothingMethod,Filter,BuffSell,i);


                  
      //
      //
      //
      //
      //
      
      buffer1[i] = EMPTY_VALUE;
      buffer2[i] = EMPTY_VALUE;
      buffer3[i] = EMPTY_VALUE;
      buffer4[i] = EMPTY_VALUE;

      
         if (IndBuy!=EMPTY_VALUE)//условие нижнего экстремума, бары красные
            
            {
              
              buffer1[i] = High[i];
              buffer2[i] = Low[i];
              if (Close[i]>Open[i]) { buffer3[i] = Close[i]; buffer4[i] = Open[i]; }  
              else                  { buffer4[i] = Close[i]; buffer3[i] = Open[i]; }
              Comment ("***SELL!***");   //условие сильной перепроданности
            }                   
         if (IndSell!=EMPTY_VALUE)//условие верхнего экстремума, бары зеленые
            {
               
               buffer1[i] = Low[i];
               buffer2[i] = High[i];
               if (Close[i]<Open[i]) { buffer3[i] = Close[i]; buffer4[i] = Open[i]; }  
               else                  { buffer4[i] = Close[i]; buffer3[i] = Open[i]; }  
               Comment ("***BUY!***"); //условие сильной перекупленности
            }  
                
         
   }
   return(0);
}