Add moving average, based on Alejandro's patch.