Code for Moving Average indicator

 
I have a question about Moving Average indicator.
I got wrong result from "Moving Averages" indicator in some case. (It was happened after recovery from network trouble)
I checked the code of indicator, and I found strange part.

---- Original start -----
void sma()
{
double sum=0;
int i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
if(pos<MA_Period) pos=MA_Period;
for(i=1;i<MA_Period;i++,pos--)
sum+=Close[pos];

//---- main calculation loop
while(pos>=0)
{
sum+=Close[pos];
ExtMapBuffer[pos]=sum/MA_Period;
sum-=Close[pos+MA_Period-1];
pos--;
}
------ Original End-----

Bolded part should be below, I think.
How do you think?

if(ExtCountedBars<MA_Period) pos=MA_Period;
else pos+= MA_Period;
for(i=1;i<MA_Period;i++,pos--)
sum+=Close[pos];


Kiriri
Reason: