The oneline solution is:
Here,accumulator = (alpha * new_value) + (1.0 - alpha) * accumulator
Accummulator - holds the value being tracked
alpha - value between 0 and 1.
The more aggressive the alpha (closer to 1) the faster the moving average adapts to the recent values. This is an exponential moving average.