Newest Bars Are Not Update

 

Hi all,


I have constructed some custom indicators lately and I had a problem that all newest bars are not updated. They stayed flat at zero.


Here's my code, can someone please advise? Thank you.


if(Bars<=MA_Period) return(0);

i=Bars-counted_bars-1;

Print("Bar is ", Bars);
Print("Counted Bars is ", counted_bars);

while(i>=0)
{
for (j=0; j<20; j++)
rocmomentum[j]=iMomentum(NULL,0,ROC_Period,PRICE_OPEN,i+j);

rocMA = iMAOnArray(rocmomentum,0,14,0,2,0);

if (i > Bars-counted_bars-1-ROC_Period) Buf_0[i]=0;
else Buf_0[i]=rocMA;
RefreshRates();

i--;
}

Reason: