RSI mtf array

 

Hi,

My question is about sliding the buffer in custom indicator.

E.g:

#define MAX_LOOK_BACK 5
int start()
{
int limit;
   int counted_bars = IndicatorCounted();
   
   //---- check for possible errors
   if(counted_bars < 0)
      return(-1);
   //---- the last counted bar will be recounted
   if(counted_bars > 0)
      counted_bars--;
   limit=Bars-counted_bars;
   //---- main loop
   Print("indicator limit: ", limit);
   
   if(MAX_LOOK_BACK < limit)
      limit = MAX_LOOK_BACK;
   //Calculate from right to left
   for(int i = 0; i < limit; i++)
   {
     rsiBuf[i] = iRSI(Symbol(), NULL, 14, PRICE_CLOSE, i);
   }
}

While running indicator will calculate the latest RSI values of the latest 5 bars. If for example in a situation that limit==2 (and limit==2 happens alot in my tests when calling via iCustom in a EA) then it will calculate bar 0 and bar 1 values and write to RSI[0] and RSI[1] respectively and won't touch the rest of the buffer. Every custom indicator I've seen is written this way. Shouldn't we slide the buffer if limit < MAX_LOOK_BACK ? as it overwrites the RSI[0] and RSI[1] but the previous values of these elements should be in RSI[2] and RSI[3] am I right?

To visualise :

Tick=0 AND limit = 5 ==> RSI[0] = 33.33 RSI[1] =44,44 RSI[2]=55,55 RSI[3]=66,66 RSI[4] = 77.77

Now assume latest 2 RSI values are 88,88 and 99,99 and array will look like below:

Tick=1 AND limit = 2 ==> RSI[0] = 88,88 RSI[1] =99.99 RSI[2]=55,55 RSI[3]=66,66 RSI[4] = 77.77

BUT shouldn't it be this:

Tick=1 AND limit = 2 ==> RSI[0] = 88,88 RSI[1] =99.99 RSI[2]=33,33 RSI[3]=44,44 RSI[4] = 55.55

Why all indicators written this way and there's no sliding of values. And why they draw trend lines correctly.

You can check this example as well: https://docs.mql4.com/customind/IndicatorCounted

 
anybody even hints will be appreciated?
Reason: