The EWMA algorithm requires a decay factor, alpha. The larger the alpha, the more the average is biased towards recent history. The alpha must be between 0 and 1, and is typically a fairly small number, such as 0.04. We will discuss the choice of alpha later.
The algorithm works thus, in pseudocode:
Multiply the next number in the series by alpha.
Multiply the current value of the average by 1 minus alpha.
Add the result of steps 1 and 2, and store it as the new current value of the average.
Repeat for each number in the series.
There are special-case behaviors for how to initialize the current value, and these vary between implementations. One approach is to start with the first value in the series; another is to average the first 10 or so values in the series using an arithmetic average, and then begin the incremental updating of the average. Each method has pros and cons.
I suppose the best thing for me to do is create a function - any pointers?