Weighted Moving Average
systemic:core-wmaIndicatorsfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Window | integer | The lookback period defining how many data points are included in each WMA calculation. This is a **constant** parameter—it cannot vary dynamically. |
| Price | floatarray | The numeric series to be smoothed using weighted averaging. Each value receives a weight proportional to its recency. |
Outputs
| Name | Type | Description |
|---|---|---|
| WMA | floatarray | A 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.
Where for linear weighting: , so the oldest point gets weight 1, and the most recent gets weight .
The Mathematics: Why Linear Weights?
Expanded Formula
For an -period WMA, the formula expands to:
The denominator is the triangular number formula:
For example, a 5-period WMA divides by .
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
| Position | Age | Weight | Percentage of Total |
|---|---|---|---|
| 1 | Oldest | 1 | 6.7% |
| 2 | 2 | 13.3% | |
| 3 | Middle | 3 | 20.0% |
| 4 | 4 | 26.7% | |
| 5 | Newest | 5 | 33.3% |
| Total | 15 | 100% |
The most recent price contributes 5× more to the average than the oldest price.
Worked Example
Given 5 daily closing prices: 102, 104, $103
| Day | Price | Weight | Price × Weight |
|---|---|---|---|
| 1 | $100 | 1 | $100 |
| 2 | $102 | 2 | $204 |
| 3 | $101 | 3 | $303 |
| 4 | $104 | 4 | $416 |
| 5 | $103 | 5 | $515 |
| Sum | 15 | $1,538 |
Compare to SMA:
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
| Aspect | SMA | WMA | EMA |
|---|---|---|---|
| Weight scheme | Equal (1/n each) | Linear (1, 2, ..., n) | Exponential decay |
| Responsiveness | Slowest | Moderate | Fastest |
| Smoothness | Highest | Moderate | Lowest |
| Memory | None beyond window | None beyond window | Infinite (decaying) |
| Best for | Long-term trends | Balanced analysis | Short-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 producesnullat that exact position in the output; it is never carried forward and never zero-filled. - Warm-up is
null, not zero: the firstwindow - 1observed bars have no full window behind them and arenull. Once real history accumulates, every value is a genuinewindow-bar weighted average — there are no fabricated early values to discount. - Live execution returns exactly one datapoint — the current bar's WMA — which is
nullwhen 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
| Window | Behavior | Typical Use |
|---|---|---|
| 5-10 | Very responsive, noisy | Scalping, intraday |
| 10-20 | Quick signals, some noise | Day trading, swing entries |
| 20-50 | Balanced trend following | Swing trading |
| 50-100 | Smooth, delayed signals | Position trading |
| 100-200 | Very smooth, significant lag | Long-term trend identification |
Choosing Your Window
Consider:
- Trading frequency — Shorter windows for more frequent trades
- Asset volatility — Higher volatility may need longer windows to reduce noise
- Signal clarity vs. timeliness — Longer = clearer but later signals
Trading Applications
1. Trend Identification
| Condition | Interpretation |
|---|---|
| Price > WMA | Bullish bias |
| Price < WMA | Bearish bias |
| WMA slope rising | Uptrend strengthening |
| WMA slope falling | Downtrend strengthening |
| WMA flattening | Trend 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
| Signal | Condition |
|---|---|
| Bullish | Short WMA crosses above Long WMA |
| Bearish | Short WMA crosses below Long WMA |
| Confirmation | Both 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:
- Calculate WMA on daily closes (20-period)
- Track the difference between consecutive WMA values (WMA slope)
- When slope transitions from positive to near-zero after an uptrend, consider tightening stops
- 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
- Weighted Moving Average - Investopedia — Calculation and basic interpretation
- Weighted Moving Average - Fidelity — Practical trading applications
- Triangular Numbers - Wikipedia — Mathematical foundation of WMA denominator
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]
| Dimension | Stocks | Crypto | Notes |
|---|---|---|---|
| Popularity | 6/10 | 5/10 | Less popular than SMA and EMA; niche usage among traders seeking balanced responsiveness |
| Reliability | 7/10 | 6.5/10 | Consistent across asset classes; linear weighting provides predictable behavior |
| Complexity | 3.5/10 | 3.5/10 | Simple concept—linear weights—but slightly more complex than SMA |
| Versatility | 7/10 | 7/10 | Works on any timeframe and asset; can be paired with other MAs for crossover strategies |
| Recent Interest | 5/10 | 5/10 | Steady but modest interest; EMA often preferred for its infinite memory |