MQL4 Custom Indicator : Buffer Lost the Value /Buffer Resets Calculations ??!!

 

Hi Guys 

i have a problem  and i need help ,

the problem with custom indicator buffer , i have create a condition to check if  the criteria are meet and give it as number one 

and if new criteria  also are meet give it as one plus the previous counts (i.e counter for the specific criteria )

the problem When i Hit the " Skip to " button or fast forword the speed the counts buffer gives me worng results "SOMETIMES" !!!!

just Like in the Middle of somewhere its resets the counts buffer ???

Check my code & the Picture and please help me guys ,

thanks .


//+------------------------------------------------------------------+
//|                                                        DDex4.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property  indicator_separate_window 
#property indicator_buffers 2
#property indicator_color1 Red  
   double Buf_0[],Buf_0Count[];
   
   

 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
   
   SetIndexBuffer(0,Buf_0);
   SetIndexStyle(0,DRAW_NONE);
   SetIndexEmptyValue(0,0);

//---------------------------------------- 
   SetIndexBuffer(1,Buf_0Count);
   SetIndexLabel(1,"Buf_0Count"); 
   SetIndexStyle(1,DRAW_LINE,EMPTY,3,clrWhite);
   SetIndexArrow(1,117);
   SetIndexEmptyValue(1,0);
//-----------------------------------------           
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) 
  {
//---
       
       int i,                          
       Counted_bars;                  
        
        Counted_bars=IndicatorCounted(); 
        i=Bars-Counted_bars-1; 
      
      if (i>20-1)                 // If too many bars ..
      i=20-1;
         
           while(i>=0)                      // Loop for uncounted bars
     { 
      
           
     if(Close[i+4]> Close[i+3]&& Close[i+4]> Close[i+2]&& Close[i+4]> Close[i+1]&& Close[i+4]> Close[i]&&
        Close[i+4]> Close[i+5]&& Close[i+4]> Close[i+6]&& Close[i+4]> Close[i+7]&& Close[i+4]> Close[i+8]) 
          
                                                                             
         {           
             Buf_0[i]=Close[i];            
             Buf_0Count[i]+=1;
         }
          
          Buf_0Count[i]=Buf_0Count[1];  
       
         i-- ;
      }
   Comment(Buf_0Count[1]);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
test.png  121 kb
Reason: