1990issue C041-11
Constructing incremental moving average filters
Simple, linear, and exponential averages all smooth ordered observations over a stated lookback, but they assign different weights to old versus recent data. A one-pass routine can avoid repeating a single-date average by updating a running sum, computing the linear weight total once, or retaining the prior exponential average.
- When many dates are required, a routine that fills an entire output series in one pass avoids repeating a single-date average call at each date.
- After the first simple-average window sum is known, the next running sum subtracts the observation that leaves the window and adds the observation that enters it.
- A linear moving average divides by the sum of integer weights from 1 through the lookback, and that weight total can be computed once outside the inner loop.
- An exponential average blends the newest observation with the prior average, so that prior value must be retained or the history is rebuilt.
Filling the output series in one pass
Editorial interpretation: TradersWeek treats a moving average as retained state rather than a one-line formula. The construction problem is naming what must be carried from the previous bar so the next simple, linear, or exponential value is exact without rebuilding the window. The archive facts describe only the historical workflow that follows.
When many dates are required, invoking a single-date average once per date repeats call overhead. A routine that fills an entire output series in one pass avoids that repetition.
Simple, linear, and exponential averages all smooth ordered observations over a stated lookback, but they assign different weights to old versus recent data.
Equal weights and the running sum
A simple moving average gives every observation in the window the same weight, so an old change offsets a new change of the same size.
After the first simple-average window sum is known, the next sum is obtained by subtracting the observation that leaves the window and adding the observation that enters it. That retained window total is the running sum.
For a 10-period simple average on 10 successive output dates, that running-sum update replaces 100 additions and 10 divisions with 28 additions and 10 divisions.
Linear weights and a once-computed total
A linear moving average multiplies the oldest point by 1 and the newest by the lookback length, then divides by the sum of those integer weights rather than by the period count.
The linear weight total from 1 through L equals L times (L plus 1) divided by 2 and can be computed once, outside the inner loop.
A recursive exponential blend
An exponential average is recursive: the current value blends the newest observation with the prior average, so that prior value must be retained or the history is rebuilt.
The exponential blending weight for a chosen period length can be written as 2 divided by (period length plus 1).
Integer totals and overflow
Integer construction requires postponing division until the last step and guarding overflow, because a long-period linear weighted sum can exceed a 32-bit integer range.
A scaled integer stores a price in whole units of the smallest tick so integer arithmetic can replace floating-point arithmetic. Division is still postponed until the last step.
All readings on this track · 41 readings
- 1984Matching average age across price filters
- 1984Residual-impact construction of exponential smoothers
- 1988Constructing simple and exponential moving averages as specified filters
- 1989Evaluating smoothed free reserves and funds-discount spreads
- 1990Integer construction of moving averages and exponential smoothing
- 1990Constructing incremental moving average filters
- 1991Constructing a double-smoothed stochastic oscillator
- 1991Constructing an exponential average from a smoothing weight
- 1991Constructing a double-smoothed momentum oscillator family
- 1991Competing certainty rules from exponential-average conditions
- 1991Hybrid construction of a mechanical timing system from smoothed signals
- 1991Constructing an exponential smoother from a moving-average length
- 1991Equivalent relative-strength-index constructions from a ratio and from smoothed momentum
- 1991Constructing the true strength index from double-smoothed momentum
- 1991True strength index from signed, double-smoothed momentum
- 1992Constructing exponential averages from simple lookbacks
- 1992Constructing exponential averages by the smoothing constant, startup length and lag
- 1992Nested range smoothing and windowed high-low damping
- 1992A weekly equity stance from the discount-bill spread
- 1993Double-smoothed stochastics momentum index construction
- 1993Constructing the true strength index with double exponential smoothing
- 1994Polarized fractal efficiency with a shared exponential smoother
- 1994Five-interval exponential smoothing of ten-interval signed path-efficiency
- 1994Hand-ranked price-volume series with stacked smoothing and stochastic
- 1995Range expansion filter on multi-horizon averages
- 1995The exponential smoothing constant from averaging lag
- 1997Construct a nested-average rainbow band and oscillator
- 1998Filter stacks that combine a moving average with exponential smoothing
- 2002Smoothed relative-strength construction from wilder-averaging and a price prefilter
- 2003Reverse-engineered RSI price targets
- 2004Piecewise trend quality from moving-average reversals
- 2004Nested smoothing recipes versus unaudited oscillator experiments
- 2008Weight construction beyond the N-day label
- 2010A consensus filter for objective RSI and smoothing construction
- 2012Sentiment-zone oscillator from signed closes
- 2012Classic RSI one-over-N smoothing versus the standard exponential average
- 2013Why exponential smoothing uses two over n plus one
- 2015Constructing ratio indicators with moving-average and exponential-smoothing weights
- 2015Slow relative-strength index from an exponentially smoothed price
- 2017Rebuilding the relative strength index as open-scale buy-sell pressure
- 2017Comparing Wilder and exponential smoothing inside a relative-strength index