Moving average simulation code