Systemicalpha

Weighted Moving Average

systemic:core-wmaIndicatorsfunction1 cr

Inputs

NameTypeDescription
WindowintegerThe lookback period defining how many data points are included in each WMA calculation. This is a **constant** parameter—it cannot vary dynamically.
PricefloatarrayThe numeric series to be smoothed using weighted averaging. Each value receives a weight proportional to its recency.

Outputs

NameTypeDescription
WMAfloatarrayA smoothed numeric series where each value represents the weighted average of the preceding `window` data points, with linear weights favoring recent values.

The Weighted Moving Average addresses a fundamental limitation of the Simple Moving Average: treating all data points equally. In reality, recent prices are often more relevant to current market conditions than older ones. WMA solves this by assigning linearly increasing weights to each data point, with the most recent price receiving the highest weight.

WMA=∑i=1n(wi×Pi)∑i=1nwiWMA = \frac{\sum_{i=1}^{n} (w_i \times P_i)}{\sum_{i=1}^{n} w_i}

Where for linear weighting: wi=iw_i = i, so the oldest point gets weight 1, and the most recent gets weight nn.


The Mathematics: Why Linear Weights?

Expanded Formula

For an nn-period WMA, the formula expands to:

WMAn=1⋅P1+2⋅P2+3⋅P3+⋯+n⋅Pn1+2+3+⋯+nWMA_n = \frac{1 \cdot P_1 + 2 \cdot P_2 + 3 \cdot P_3 + \cdots + n \cdot P_n}{1 + 2 + 3 + \cdots + n}

The denominator is the triangular number formula:

∑i=1ni=n(n+1)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}

For example, a 5-period WMA divides by 5×62=15\frac{5 \times 6}{2} = 15.

Why Linear (Not Arbitrary)?

Linear weights create a constant rate of decay in importance. Each step back in time reduces influence by the same absolute amount. This provides:

  • Predictable behavior — You know exactly how much weight each period contributes
  • Symmetry — The weight distribution forms a simple triangle
  • Balance — More responsive than SMA, but not as jumpy as exponential weighting

Weight Distribution Visualization

flowchart LR
    subgraph Window["5-Period WMA"]
        P1["Day 1<br/>Weight: 1<br/>(6.7%)"]
        P2["Day 2<br/>Weight: 2<br/>(13.3%)"]
        P3["Day 3<br/>Weight: 3<br/>(20%)"]
        P4["Day 4<br/>Weight: 4<br/>(26.7%)"]
        P5["Day 5<br/>Weight: 5<br/>(33.3%)"]
    end
    
    subgraph Calc["Calculation"]
        SUM["Σ(Price × Weight)"]
        DIV["÷ 15"]
        WMA["WMA Value"]
    end
    
    P1 --> SUM
    P2 --> SUM
    P3 --> SUM
    P4 --> SUM
    P5 --> SUM
    SUM --> DIV --> WMA

Weight Distribution Table

PositionAgeWeightPercentage of Total
1Oldest16.7%
2213.3%
3Middle320.0%
4426.7%
5Newest533.3%
Total15100%

The most recent price contributes 5× more to the average than the oldest price.


Worked Example

Given 5 daily closing prices: 100,100, 102, 101,101, 104, $103

DayPriceWeightPrice × Weight
1$1001$100
2$1022$204
3$1013$303
4$1044$416
5$1035$515
Sum15$1,538
WMA=153815=102.53WMA = \frac{1538}{15} = 102.53

Compare to SMA: 100+102+101+104+1035=102.00\frac{100 + 102 + 101 + 104 + 103}{5} = 102.00

The WMA is slightly higher because it weights the recent higher prices more heavily.


Moving Average Comparison

flowchart TD
    subgraph Types["Moving Average Types"]
        SMA["SMA<br/>Equal weights<br/>All periods = 1/n"]
        WMA["WMA<br/>Linear weights<br/>Recent = n, Oldest = 1"]
        EMA["EMA<br/>Exponential decay<br/>Recent heavily weighted"]
    end
    
    subgraph Response["Price Responsiveness"]
        SLOW["Slowest response<br/>Most lag"]
        MED["Balanced response<br/>Moderate lag"]
        FAST["Fastest response<br/>Least lag"]
    end
    
    SMA --> SLOW
    WMA --> MED
    EMA --> FAST
AspectSMAWMAEMA
Weight schemeEqual (1/n each)Linear (1, 2, ..., n)Exponential decay
ResponsivenessSlowestModerateFastest
SmoothnessHighestModerateLowest
MemoryNone beyond windowNone beyond windowInfinite (decaying)
Best forLong-term trendsBalanced analysisShort-term signals

Missing Data

window means window observed bars — not calendar slots. A closed-market slot (weekend, holiday) or a genuine data gap never fabricates a value and never poisons the average with a stale or zero substitute.

  • Gaps are bridged, not broken: the window slides over the bars that actually have data. A 5-period WMA spanning a weekend weights the five most recent trading days — Friday and the following Monday are adjacent, exactly as a trader reads the chart.
  • Missing slots stay null: a data gap or closed-market slot produces null at that exact position in the output; it is never carried forward and never zero-filled.
  • Warm-up is null, not zero: the first window - 1 observed bars have no full window behind them and are null. Once real history accumulates, every value is a genuine window-bar weighted average — there are no fabricated early values to discount.
  • Live execution returns exactly one datapoint — the current bar's WMA — which is null when the current bar's data, or enough trading history behind it, is missing.

Minimum Data Requirement

The window parameter defines how many observed bars are needed. If your input has fewer calendar points than the window, the module raises an error; if it has enough calendar points but too few observed (non-null) bars, the warm-up prefix simply stays null until enough real observations accumulate.


Parameter Selection

WindowBehaviorTypical Use
5-10Very responsive, noisyScalping, intraday
10-20Quick signals, some noiseDay trading, swing entries
20-50Balanced trend followingSwing trading
50-100Smooth, delayed signalsPosition trading
100-200Very smooth, significant lagLong-term trend identification

Choosing Your Window

Consider:

  1. Trading frequency — Shorter windows for more frequent trades
  2. Asset volatility — Higher volatility may need longer windows to reduce noise
  3. Signal clarity vs. timeliness — Longer = clearer but later signals

Trading Applications

1. Trend Identification

ConditionInterpretation
Price > WMABullish bias
Price < WMABearish bias
WMA slope risingUptrend strengthening
WMA slope fallingDowntrend strengthening
WMA flatteningTrend exhaustion or consolidation

2. Dynamic Support/Resistance

In trending markets, the WMA often acts as a dynamic level:

  • Uptrend: Price pulls back to WMA, then bounces (support)
  • Downtrend: Price rallies to WMA, then reverses (resistance)

3. Crossover Strategies

SignalCondition
BullishShort WMA crosses above Long WMA
BearishShort WMA crosses below Long WMA
ConfirmationBoth WMAs sloping in same direction after cross

Real-World Applications

1. Momentum Transition Detection

WMA's linear weighting makes it particularly useful for detecting early momentum shifts. When price action changes character, the WMA responds faster than an SMA but without the jitter of an EMA.

Application: Monitor the WMA slope (rate of change). A flattening WMA after a sustained trend often precedes a reversal before price itself shows clear reversal patterns.

Strategy concept:

  1. Calculate WMA on daily closes (20-period)
  2. Track the difference between consecutive WMA values (WMA slope)
  3. When slope transitions from positive to near-zero after an uptrend, consider tightening stops
  4. Combine with volume analysis for confirmation

2. Paired WMA for Entry Timing

Using two WMAs of different periods creates a system that balances responsiveness with noise reduction.

Classic pairing: 10-period WMA (fast) with 30-period WMA (slow)

Why WMA over SMA for this?: The linear weighting ensures both averages respond proportionally to recent price changes, reducing the likelihood of false crossovers during consolidation.


Advantages

  • Recent price emphasis — Newer data influences the average more
  • Predictable weighting — Linear weights are intuitive and transparent
  • Balanced responsiveness — Faster than SMA, smoother than EMA
  • Universal applicability — Works on any asset class and timeframe

Limitations

  • Still lags — All moving averages lag price; WMA just lags less than SMA
  • Arbitrary weight scheme — Linear weights aren't derived from market theory
  • Window dependency — Signals vary significantly with window choice
  • No infinite memory — Unlike EMA, data beyond the window has zero influence

Further Reading


Indicator Assessment

%%{init: {'theme': 'base', 'themeVariables': { 'cScale0': '#2563eb', 'cScale1': '#7c3aed'}}}%%
quadrantChart
    title WMA Indicator Assessment
    x-axis Low Complexity --> High Complexity
    y-axis Low Reliability --> High Reliability
    quadrant-1 High Value
    quadrant-2 Specialized
    quadrant-3 Limited Use
    quadrant-4 Accessible
    Stocks: [0.35, 0.70]
    Crypto: [0.35, 0.65]
DimensionStocksCryptoNotes
Popularity6/105/10Less popular than SMA and EMA; niche usage among traders seeking balanced responsiveness
Reliability7/106.5/10Consistent across asset classes; linear weighting provides predictable behavior
Complexity3.5/103.5/10Simple concept—linear weights—but slightly more complex than SMA
Versatility7/107/10Works on any timeframe and asset; can be paired with other MAs for crossover strategies
Recent Interest5/105/10Steady but modest interest; EMA often preferred for its infinite memory
Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5