What it measures
The Hull Moving Average is a moving average designed to follow price closely without becoming jagged. Ordinary averages force a trade-off: short ones react fast but are noisy, long ones are smooth but late. The HMA combines weighted averages of two lengths to cancel much of the lag, then smooths the result over a short window.
Alan Hull published it in 2005. It's used mostly for its slope: a rising HMA describes an uptrend, a falling one a downtrend, and the turns come earlier than on an EMA of the same length.
The formula in words
- Compute a weighted moving average (WMA) of the close over N ÷ 2 bars and another over N bars. A WMA gives the newest bar a weight of N, the one before N − 1, and so on.
- Take 2 × WMA(N ÷ 2) − WMA(N). Doubling the faster average and subtracting the slower one pushes the average forward and removes much of its lag.
- Smooth that series with a WMA over √N bars, rounded. The result is the HMA.
For N = 55, that's WMA(27) and WMA(55), then a final WMA over 7 bars. Pine Script has ta.hma(source, length); the script below writes the formula out with ta.wma() so each step is visible.
How traders read it
- Slope. The change from falling to rising (and back) is the main signal. It comes within a few bars of a turn, which is the point of the indicator.
- As a trend filter. A longer HMA (100 or 200) is used like any long average: longs only while it rises.
- Price versus the HMA. Because the HMA hugs price, closes across it happen often. Most traders use the slope rather than crosses.
- Two HMAs. A fast and a slow HMA can be crossed like EMAs. The crosses come earlier, and so do the false ones.
Common settings
| Length | Typical use |
|---|---|
| 9 to 21 | Short-term swings and intraday charts |
| 55 | Swing trading on hourly to daily charts |
| 100 to 200 | Long-term trend filter |
There's no standard length. Because the HMA reacts faster, traders often use a longer HMA where they would use a shorter EMA. The moving average calculator computes the SMA, EMA and WMA, the HMA's building block, for any list of closes.
Pine Script v6 code
The complete, self-contained script is below. Copy it into a new indicator in TradingView's Pine Editor, or download the .pine file.
//@version=6
indicator("Hull Moving Average", shorttitle = "HMA", overlay = true)
src = input.source(close, "Source", group = "Calculation")
len = input.int(55, "Length", minval = 2, group = "Calculation")
upCol = input.color(color.teal, "Rising", group = "Display")
dnCol = input.color(color.red, "Falling", group = "Display")
colorBars = input.bool(false, "Colour the price bars by slope", group = "Display")
// HMA = WMA(2 x WMA(n / 2) - WMA(n), sqrt(n)). Same result as ta.hma(src, len).
halfLen = math.max(1, int(len / 2))
sqrtLen = math.max(1, math.round(math.sqrt(len)))
hma = ta.wma(2 * ta.wma(src, halfLen) - ta.wma(src, len), sqrtLen)
rising = hma > hma[1]
turnsUp = rising and not rising[1]
turnsDown = not rising and rising[1]
plot(hma, "HMA", color = rising ? upCol : dnCol, linewidth = 3)
plotshape(turnsUp, "Turns up", shape.triangleup, location.belowbar, upCol, size = size.tiny)
plotshape(turnsDown, "Turns down", shape.triangledown, location.abovebar, dnCol, size = size.tiny)
barcolor(colorBars ? (rising ? upCol : dnCol) : na, title = "Bar colour")
alertcondition(turnsUp, "HMA turns up", "The Hull Moving Average turned up on {{ticker}} ({{interval}}) at {{close}}")
alertcondition(turnsDown, "HMA turns down", "The Hull Moving Average turned down on {{ticker}} ({{interval}}) at {{close}}")The HMA is drawn on the price chart in green while rising and red while falling, with triangles on each turn. An option colours the price bars by the HMA's slope.
Two alert conditions fire when the slope turns. A turn compares the current HMA with the previous bar's, so it's provisional until the bar closes; set alerts to Once per bar close.
Add it to your chart
- Open any chart on TradingView and open the Pine Editor.
- Create a new indicator, delete the template code and paste the script.
- Click Save, then Add to chart. Change lengths and levels from the indicator's settings.
Stuck on an error? See how to add a Pine Script indicator to TradingView.
Pitfalls
- Overshoot. The lag-cancelling step pushes the average forward. After a sharp reversal the HMA can briefly run past price before it turns.
- Many turns. Short HMAs turn often in ranges. Pair them with a longer filter or a minimum slope.
- Comparing lengths with EMAs. A 55-period HMA doesn't behave like a 55-period EMA. Compare them on the chart rather than assuming.
- Live-bar turns. The slope on the unfinished bar can flip back before the close.
Related reading
- Pine Script EMA crossover strategy: a complete v6 example with stops and costs
- Pine Script v6 for beginners: the concepts that make everything click
- Moving Average Calculator (free tool)
- ATR Stop-Loss Calculator (free tool)
The script is an educational example: test it on your own markets before relying on it. Indicators describe the past; they don't predict the future. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.