Calculate a five-period WMA by hand
Use these hypothetical closing prices in chronological order: 100, 102, 101, 105, 109. They illustrate the arithmetic and are not a market backtest. Assign the highest weight to 109.
| Observation | Close | Weight | Normalized weight | Close × weight |
|---|---|---|---|---|
| Oldest | 100 | 1 | 1/15 | 100 |
| Second | 102 | 2 | 2/15 | 204 |
| Third | 101 | 3 | 3/15 | 303 |
| Fourth | 105 | 4 | 4/15 | 420 |
| Newest | 109 | 5 | 5/15 | 545 |
WMA = (100 + 204 + 303 + 420 + 545) / 15 = 104.8
The ordinary average of these same five prices is 103.4. The WMA is higher because the larger recent values carry more weight. That ordering can reverse when recent prices are lower. Dividing 1,572 by five would give 314.4, which is a weighted sum divided by the wrong denominator.
Normalization gives a useful check: the fractions in the table sum to one. With positive weights and complete numeric inputs, WMA must lie between the smallest and largest prices in its window. If every price equals 100, the result must be 100 too.
What changes when the next bar arrives?
Suppose the next hypothetical close is 107. The five-price window becomes 102, 101, 105, 109, 107. The old 100 leaves entirely. Every surviving price moves down one weight, while 107 receives weight five. The denominator stays at 15.
WMA = (102×1 + 101×2 + 105×3 + 109×4 + 107×5) / 15 = 106
The latest close fell from 109 to 107, yet the WMA rose from 104.8 to 106. The whole window matters. A rising WMA does not mean the latest candle closed higher, and its slope alone is not a reversal forecast.
Changing the length also changes every normalized weight. At length 20 the divisor is 210 and the newest price receives 20/210, about 9.52%. At length five it receives 5/15, about 33.33%. A different length is a different filter, not a display adjustment.
WMA vs EMA and SMA: compare the weights
| Average | Newest weight | What happens to old prices? |
|---|---|---|
| WMA | 2/(n + 1) | Linear taper, then zero outside the window. |
| EMA | α = 2/(n + 1) | Recursive decay through the previous EMA. |
| SMA | 1/n | Equal weight, then zero outside the window. |
WMA and EMA give a new observation the same coefficient at equal length, but distribute the remaining weight differently. For n = 5, WMA weights from newest to oldest are 5/15, 4/15, 3/15, 2/15, 1/15. An established EMA has an exponential sequence starting 1/3, 2/9, 4/27, with older contributions carried through its initialized value. Matching only the newest coefficient does not make the two outputs equal.
Compare the same source and timeframe before judging either line. See the EMA guide for recursive weighting and the SMA guide for equal weights. There is no fixed number of bars by which WMA must beat another average to a crossover.
Check source, length, and bar confirmation
- Source determines the numbers being averaged. Close, open, and a high/low average can produce different lines at the same length.
- Length counts observations on the selected timeframe. The example uses the chart timeframe and starts at 20; this is an example default, not a tested optimum.
- On an open bar, close is the latest available price. Its WMA can change before the candle closes. A rule evaluated only at bar close waits longer but uses the completed bar.
- Repeated crossings around a flat average can produce whipsaws. A longer window changes sensitivity, but does not guarantee better entries or remove trading costs.
For a reproducible comparison, record the symbol, timeframe, session, source, length, and exact closed bar. Compare the Data Window values with the hand calculation before adding a trading rule. Higher-timeframe requests and external indicator sources introduce their own confirmation behavior; they are outside this chart-timeframe example.
A WMA indicator to inspect in TradingView
Paste this Pine Script v6 indicator into the Pine Editor and add it to the chart. Set Length to five and Source to Close when checking a five-bar calculation. It draws one WMA line; it does not place orders or create alerts.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//@version=6
indicator(title="Weighted Moving Average", overlay=true, max_labels_count=500)
// Inputs
length = input.int(20, "Length", minval=1)
src = input.source(close, "Source")
// WMA Calculation
wma_val = ta.wma(src, length)
// Plot
plot(wma_val, "WMA", color.rgb(41, 98, 255, 0), 2)Copy this indicator into the TradingView Pine Editor.
For function arguments and API details, use the ta.wma reference. This page focuses on interpreting the weights and verifying the output.
Build a WMA condition in Pineify
The Visual Editor includes WMA with Source and Length inputs. For a custom rule, describe the required source, length, chart timeframe, and close-confirmation behavior to the AI Coding Agent. Review the generated condition against those choices before testing it on TradingView.
Explore the AI Coding AgentPrefer configurable inputs? See the Visual Editor.
WMA questions
What is a weighted moving average?
On TradingView, WMA is a moving average with linear weights: the latest observation receives weight n and the oldest receives weight 1. Divide the weighted sum by n(n + 1)/2. It describes the chosen source over a finite window; it does not predict the next price.
What is the weighted moving average formula?
WMA = (n × P0 + (n − 1) × P1 + … + 1 × P(n−1)) / (n(n + 1)/2), where P0 is the newest observation. The denominator is the sum of the weights, not the number of prices. For length 5, divide by 15.
Does "weight moving average" mean a different indicator?
The usual indicator name is weighted moving average, abbreviated WMA. A search for a weight moving average formula generally refers to the same calculation. Check the implementation: a generic weighted average can use arbitrary weights, while TradingView WMA uses linearly decreasing weights.
Is WMA faster or better than EMA?
Neither has a universal trading advantage. At the same length n, WMA and the standard EMA give the newest observation weight 2/(n + 1). WMA then uses a linear taper with a fixed cutoff; EMA uses exponential decay through its previous value. Their reactions depend on the price sequence and EMA initialization.
Does WMA repaint on TradingView?
A WMA calculated from close can move while the current bar is open because close is changing. Waiting for that bar to close confirms that observation but delays the decision. The example uses the chart timeframe and no future bars. External indicator sources, other timeframes, and revised market data require separate checks.
What WMA length should I use?
Choose a length that matches the observation window you want to study, then test any trading rule separately. The example starts at 20 because that is the Pineify WMA configuration default, not because 20 is best. A 20-bar WMA on a 15-minute chart and on a daily chart describe different time horizons.
Can Pineify create WMA conditions?
Pineify Visual Editor includes WMA with configurable Source and Length inputs. You can also describe a WMA condition to the AI Coding Agent and inspect the resulting script. Specify the source, chart timeframe, length, and whether the decision waits for bar close. Generated code still needs chart and strategy validation.
Sources and calculation scope
- TradingView: moving average calculations and weighting
- TradingView Pine Script v6: ta.wma reference
- TradingView Pine Script: repainting and fluid prices
Sources checked October 16, 2026. The numeric examples are hypothetical, use complete observations, and show arithmetic rather than investment results.
Educational information, not investment advice. An indicator calculation or successful compilation does not establish that a trading strategy is profitable.