Here is the calculation to get the correct SMMA of an array :

Code:
for(int i=500;i>=0;i--){
      if(i==500)
      for(int j=0;j<=Period-1;j++){
         SMMA[i]+=Close[i+j]*(1/Period);
      }
      else SMMA[i]=(SMMA[i+1]*(Period-1)+Close[i])/Period;
   }
Close can be replaced by any array of values.