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 script

The 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.

HMA intermediate windows under two rounding conventions
Length nn / 2sqrt(n)Truncate: half / rootNearest: half / root
115.53.3175 / 36 / 3
157.53.8737 / 38 / 4
16848 / 48 / 4
100501050 / 1050 / 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.

Illustrative step response, rounded to two decimals in price units
Bars after stepPriceSMA(16)EMA(16)HMA(16)
1110.00100.63101.18101.31
4110.00102.50103.94108.12
8110.00105.00106.33112.51
12110.00107.50107.77111.14
16110.00110.00108.65110.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.

Pine Script v6
//@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

HMA applies a WMA to the difference between twice a half-period WMA and a full-period WMA. The final smoothing window is based on the square root of the full period. A manual implementation must also specify how it converts fractional window lengths to integers.

State the convention for both the half-period and square-root windows. For length 15, truncation gives windows of 7 and 3; rounding to the nearest integer gives 8 and 4. These are different filters. Use ta.hma for the TradingView built-in calculation, and compare a manual version against it before claiming they match.

Neither is universally better. HMA uses a subtraction step that can respond quickly and overshoot a price move. EMA uses exponential smoothing. Compare them on the same source and timeframe, and measure the outcomes that matter to your rules, such as reversal delay or repeated slope changes.

An HMA calculated from the current close changes while that bar is open. The example keeps that live line but waits for bar close before displaying a turn marker. This does not guarantee unchanged results after data corrections or when a different script introduces higher-timeframe requests or shifted plots.

Hull Suite by InSilico includes HMA, EHMA and THMA modes with band or line displays and other options. Standard HMA is one calculation. A Suite result is comparable only after checking its selected variant, effective length, source, timeframe and any plot shift.

There is no best length established for every market. The example uses 16 because its half-period and square root are integers. Pineify's visual HMA configuration defaults to 100. Neither value is a trading recommendation; test nearby lengths with fixed rules, costs and a separate evaluation period.

Sources and related reading

Sources checked October 16, 2026.

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.