//+------------------------------------------------------------------+
//|                                          RenkoWindowAnalizer.mq4 |
//|                                                           Ttomas |
//|                                                 TradeLikeAPro.ru |
//+------------------------------------------------------------------+
#property copyright "Ttomas"
#property link      "TradeLikeAPro.ru"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 2

extern int LastRes=1000;
extern int AnalizeBar=7;
extern bool Debag=True;
double Buf1[];
int Maximum=0, Minimum=0;
int init()
   {
   IndicatorBuffers(1);
   SetIndexBuffer(0,Buf1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexEmptyValue(0,0.0);
   IndicatorShortName("RenkoWindowAnalizer ");
   
   
   return(0);
   }
int deinit()
   {
   return(0);
   }
int start()
   {
  
   //ArrayResize(Buf1,Bars);
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   int limit = Bars - counted_bars -1;
      if (Debag) Print ("Сколько баров надо расчитать ",limit ); 
// if (LastRes!=0) limit=LastRes-counted_bars-1;
   Buf1[Bars-1]=0; 
   //Buf1[Bars]=0;
   for (int shift =limit; shift >= 0; shift--)
      {
      Print("shift=", shift);
      if (shift>=Bars-AnalizeBar-1) {Buf1[shift]=0; continue;} // защита на случай если попытается брать данные которых несуществует
      if (Debag) Print ("Начало цикла заполнения для бара ", shift); 
      //if (shift>LastRes) continue; //ограничение количества расчета 
      int count1=0;
      for (int k=AnalizeBar;k>=0;k--)
         {
         double op=iOpen(NULL,0,shift+k); double cl=iClose(NULL,0,shift+k);
        // if (Debag) Print("Значение цены открытия - ",op," цены закрытия - ",cl); 
         
         if (op<cl){ count1++; if (Debag) Print("Значение счетчика - ",count1); }
         if (op>cl){ count1--; if (Debag) Print("Значение счетчика - ",count1); }
         }
          if (Debag) Print("Общее значение - ",count1);
      if (count1>0) {if (Debag) Print("Увеличиваем предыдущий бар значение которого ", Buf1[shift+1]); Buf1[shift]=Buf1[shift+1]+1;}
      if (count1<0) {if (Debag) Print("Увеличиваем предыдущий бар значение которого ", Buf1[shift+1]); Buf1[shift]=Buf1[shift+1]-1;}
      if (Debag) Print("Значение буфера на ",shift," баре равно ",Buf1[shift]); 
      }

   return(0);
   }