Pine Script indicators
Hull Moving Average: Formula and Rounding
The Hull Moving Average (HMA) combines weighted moving averages to reduce delay, then smooths the result with a shorter window. That subtraction can also push HMA beyond recent prices. To reproduce it, specify the price source, length and integer rounding rule before comparing curves.
This guide shows the calculation, a hypothetical price-step comparison and a copyable TradingView script. HMA describes price behavior; a turn in the line is not proof of a reversal.
View the HMA comparison scriptThe HMA formula, one window at a time
A WMA assigns weights from 1 for the oldest observation to m for the newest, then divides by m(m + 1) / 2. HMA combines two such averages of the same source before applying a third WMA.
half = integer window based on n / 2
root = integer window based on sqrt(n)
raw = 2 × WMA(source, half) − WMA(source, n)
HMA = WMA(raw, root)
Alan Hull's original explanation uses integer windows and describes the compensation created by the subtraction. The TradingView HMA documentation presents the same three calculation stages. Its short formula alone does not specify every implementation detail.
Why rounding changes the result
Window lengths must be whole numbers. For positive lengths, truncation discards the fractional part; nearest-integer rounding may choose the next integer. The table compares those explicit conventions, not a claim about the internals of ta.hma.
| Length n | n / 2 | sqrt(n) | Truncate: half / root | Nearest: half / root |
|---|---|---|---|---|
| 11 | 5.5 | 3.317 | 5 / 3 | 6 / 3 |
| 15 | 7.5 | 3.873 | 7 / 3 | 8 / 4 |
| 16 | 8 | 4 | 8 / 4 | 8 / 4 |
| 100 | 50 | 10 | 50 / 10 | 50 / 10 |
Use ta.hma when you want TradingView's built-in result. When porting a manual formula, record both integer windows and compare the outputs after warm-up, including odd lengths. A match at length 16 cannot establish a match at length 15. Guard custom windows against zero at very short lengths.
Less delay can mean more overshoot
Consider an illustrative series held at 100 for 100 bars, then at 110 for every subsequent bar. All averages use length 16. HMA uses WMA windows of 8, 16 and 4; EMA uses alpha 2/17 and starts at 100. These are calculated values for invented data, not market returns or a strategy backtest.
| Bars after step | Price | SMA(16) | EMA(16) | HMA(16) |
|---|---|---|---|---|
| 1 | 110.00 | 100.63 | 101.18 | 101.31 |
| 4 | 110.00 | 102.50 | 103.94 | 108.12 |
| 8 | 110.00 | 105.00 | 106.33 | 112.51 |
| 12 | 110.00 | 107.50 | 107.77 | 111.14 |
| 16 | 110.00 | 110.00 | 108.65 | 110.11 |
HMA approaches 110 sooner in this example, exceeds it and then falls back while price stays flat. That falling slope could be mistaken for a new bearish move. The subtraction gives some observations negative effective weights, so HMA is not confined to the input price range like a positive-weight average.
Smoothness, turning-point delay and overshoot measure different things. A smooth curve can still be late; a fast curve can change direction repeatedly in a range. There is no fixed number of bars by which HMA always leads EMA or SMA.
Compare the failure cases too
- In a sustained move, measure the first confirmed turn after a defined price reversal. Keep the reversal definition identical for each average.
- In a sideways segment, count repeated slope changes and the resulting costs under the same entry and exit rules.
- After a jump followed by flat prices, inspect overshoot and recovery. A slope change caused by filter settling need not indicate a fresh price move.
Keep symbol, session, source, timeframe and sample dates fixed. Then vary length separately. Changing all of them at once makes it difficult to explain why the results differ.
Standard HMA and Hull Suite are different scopes
Standard HMA is a calculation. InSilico's Hull Suite publication combines HMA, EHMA and THMA variants with band or single-line displays, trend coloring and additional settings. A band color in that script is not automatically the same condition as a one-bar change in standard HMA.
Before comparing two charts, check the variant, effective length, price source, timeframe and whether a displayed line references an earlier bar. A length multiplier alone does not reproduce higher-timeframe OHLC aggregation. Use the Hull Suite guide for the expanded indicator; this page keeps standard HMA as its focus.
Compare HMA, SMA and EMA in Pine Script
This indicator plots all three built-in averages from the same source and period. The triangles mark confirmed HMA slope changes. It places no orders and calculates no trading returns.
//@version=6
indicator("HMA, SMA and EMA comparison", overlay=true)
length = input.int(16, "Length", minval=2)
source = input.source(close, "Source")
hma = ta.hma(source, length)
sma = ta.sma(source, length)
ema = ta.ema(source, length)
plot(hma, "HMA", color.blue, 2)
plot(sma, "SMA", color.orange, 1)
plot(ema, "EMA", color.purple, 1)
// Mark a slope change only after the chart bar closes.
turnUp = barstate.isconfirmed and hma > hma[1] and hma[1] <= hma[2]
turnDown = barstate.isconfirmed and hma < hma[1] and hma[1] >= hma[2]
plotshape(turnUp, "HMA turns up", shape.triangleup, location.belowbar, color.blue, size=size.tiny)
plotshape(turnDown, "HMA turns down", shape.triangledown, location.abovebar, color.orange, size=size.tiny)Copy into the TradingView Pine Editor, then select Add to chart.
The lines still update during an open bar. A marker waits for barstate.isconfirmed, so it is only available at that bar's close. Waiting removes provisional intrabar turns from these markers at the cost of waiting for confirmation. See TradingView's repainting explanation.
Use standard candles for a price-based comparison. If you choose a synthetic source or request another timeframe, inspect those data rules separately. A confirmed marker alone does not define a trade: specify entry timing, exits, sizing and costs before evaluating a strategy.
Build a comparison with Pineify
Pineify's Visual Editor includes HMA with configurable source and length. Its default length is 100; the example above uses 16 to make the window arithmetic clear. For custom rules, describe the comparison to the AI Coding Agent, then review the generated source and check it on TradingView.
Plot HMA, SMA and EMA using the same close source and length. Mark HMA slope changes only on closed bars. Keep the indicators on the chart timeframe, and explain each marker before adding any strategy orders.Build HMA rules with the AI Coding Agent
Prefer visual configuration? Open the Visual Editor overview. Generated code still needs review; compiling does not establish signal quality or profitability.
Hull Moving Average questions
Sources and related reading
Sources checked October 16, 2026.
- Alan Hull: The Hull Moving Average
Original formula, integer periods and lag compensation.
- TradingView: Hull Moving Average
The three weighted-average calculation stages.
- InSilico: Hull Suite on TradingView
Author-published description of variants and display options.
- TradingView Pine Script: Repainting
Unconfirmed prices, historical behavior and bar-close confirmation.
For the underlying averages, read the WMA guide and EMA guide.
Browse the TradingView indicators guide to compare other indicator types and their data requirements.
Educational information, not investment advice. The numerical example uses invented prices and makes no claim about returns. Trading losses, fees and slippage remain possible regardless of how smooth an indicator looks.