Older bars info in indi chart not being deleted

 

Hi All,

See chart pic below, it should be limited to maxBars=20, but keeps counting.

My putting in SetEmptyValues in init() and, in start(), the last chunk, while (i >maxBars) { arrUSD[i] =0; ... }

has no effect !

Athar.

Older bars indi chart not being deleted

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit;
   int counted_bars = IndicatorCounted();

   if (counted_bars < 0)  return(-1);
   if (counted_bars > 0)  counted_bars --;

   limit = Bars - counted_bars;

  /* if ( maxBars > 0 )
   {
      limit = MathMin (maxBars, limit); 
        
   }   
  
  */ 
   if(limit>maxBars)
      limit=maxBars;
      
      
      
   int i;
   
   for ( i = 0; i < CURRENCYCOUNT; i++ )
   {
      SetIndexStyle( i, DRAW_LINE, STYLE_SOLID, 2, currencyColors[i] );
   }   

   RefreshRates();
   
   for ( i = limit; i >= 0; i-- )
   {
      int index;
      double diff = 0.0;
      
      ArrayInitialize(currencyValues, 0.0);

      // Calc Slope into currencyValues[]  
      calcCSS( userTimeFrame, i );

      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "USD" ) != -1 ) ) || ( !showOnlySymbolOnChart && USD ) )        
      {
         arrUSD[i] = currencyValues[0];
         if ( diff == 0 ) diff += currencyValues[0]; else diff -= currencyValues[0];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "EUR" ) != -1 ) ) || ( !showOnlySymbolOnChart && EUR ) )        
      {
         arrEUR[i] = currencyValues[1];
         if ( diff == 0 ) diff += currencyValues[1]; else diff -= currencyValues[1];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "GBP" ) != -1 ) ) || ( !showOnlySymbolOnChart && GBP ) )        
      {
         arrGBP[i] = currencyValues[2];
         if ( diff == 0 ) diff += currencyValues[2]; else diff -= currencyValues[2];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "CHF" ) != -1 ) ) || ( !showOnlySymbolOnChart && CHF ) )        
      {
         arrCHF[i] = currencyValues[3];
         if ( diff == 0 ) diff += currencyValues[3]; else diff -= currencyValues[3];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "JPY" ) != -1 ) ) || ( !showOnlySymbolOnChart && JPY ) )        
      {
         arrJPY[i] = currencyValues[4];
         if ( diff == 0 ) diff += currencyValues[4]; else diff -= currencyValues[4];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "AUD" ) != -1 ) ) || ( !showOnlySymbolOnChart && AUD ) )        
      {
         arrAUD[i] = currencyValues[5];
         if ( diff == 0 ) diff += currencyValues[5]; else diff -= currencyValues[5];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "CAD" ) != -1 ) ) || ( !showOnlySymbolOnChart && CAD ) )        
      {
         arrCAD[i] = currencyValues[6];
         if ( diff == 0 ) diff += currencyValues[6]; else diff -= currencyValues[6];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "NZD" ) != -1 ) ) || ( !showOnlySymbolOnChart && NZD ) )        
      {
         arrNZD[i] = currencyValues[7];
         if ( diff == 0 ) diff += currencyValues[7]; else diff -= currencyValues[7];
      }
      
      if ( i == 1 )
      {
         ArrayCopy(currencyValuesPrior, currencyValues);
      }
      if ( i == 0 )
      {
         // Show ordered table
         ShowCurrencyTable( userTimeFrame );
      }
      
      
      // Only two currencies, show background
      if ( showOnlySymbolOnChart )
      {
         // Create background object
         int windex = WindowFind ( shortName );
         string objectName = almostUniqueIndex + "_diff_" + Time[i];
         if ( ObjectFind ( objectName ) == -1 )
         {
            if ( ObjectCreate ( objectName, OBJ_VLINE, windex, Time[i], 0 ) )
            {
               ObjectSet ( objectName, OBJPROP_BACK, true );
               ObjectSet ( objectName, OBJPROP_WIDTH, 8 );
            }
         }
         // Determine background color
         if ( MathAbs( diff ) > differenceThreshold ) 
         {
            // Check diff sign
            double cssLong = currencyValues[getCurrencyIndex(StringSubstr(Symbol(), 0, 3))];
            double cssShort = currencyValues[getCurrencyIndex(StringSubstr(Symbol(), 3, 3))];
            if ( cssLong > cssShort )
               ObjectSet ( objectName, OBJPROP_COLOR, colorDifferenceUp );
            else
               ObjectSet ( objectName, OBJPROP_COLOR, colorDifferenceDn );
         }
         else
         {
            // Below threshold
            ObjectSet ( objectName, OBJPROP_COLOR, colorDifferenceLo );
         }
      }

   }
   
  /*
  
   // set currency values to zero onn bars older than maxBars, not displayed
   
   if (i > maxBars)
   {
   arrUSD[i]= 0;
   arrEUR[i] =0;
   arrGBP[i] =0;
   arrCHF[i] =0;
   arrJPY[i] =0;
   arrAUD[i] =0;
   arrCAD[i] =0;
   arrNZD[i] =0;
   }

*/

   return(0);
}

            
Reason: