Master this remarkably smooth and low-lagging moving average in TradingView's Pinescript for precise trend identification and reversal signals.
The Hull Moving Average (HMA), created by Alan Hull, is a unique and powerful moving average designed to be extremely smooth while simultaneously having very little lag. Traditional moving averages often suffer from either being too laggy (smoothing out noise but delaying signals) or too noisy (responsive but prone to whipsaws). The HMA aims to address this dilemma by using a sophisticated weighting method to achieve both responsiveness and smoothness.
In Pinescript, the HMA stands out as a superior tool for discerning trend direction early and filtering out market noise effectively, making it a favorite among traders looking for cleaner signals.
The HMA is calculated in three steps, involving Weighted Moving Averages (WMAs):
//@version=5
indicator("My Hull Moving Average", overlay=true)
// Input for HMA length
length = input.int(20, title="HMA Length", minval=1)
// Calculate HMA using the built-in function
hmaValue = ta.hma(close, length)
// Plot the HMA line
plot(hmaValue, title="HMA", color=color.blue, linewidth=2)
HMA minimizes lag by giving more weight to recent prices and smoothing the result, making it highly effective for trend identification.
//@version=5
strategy("HMA Trend Color Strategy", overlay=true)
// Input for HMA length
length = input.int(20, title="HMA Length", minval=1)
// Calculate HMA
hmaValue = ta.hma(close, length)
// Determine HMA color based on its direction
hmaColor = hmaValue > hmaValue[1] ? color.green : color.red
// Plot the HMA line with dynamic color
plot(hmaValue, title="HMA", color=hmaColor, linewidth=2)
// Example entry logic: buy when HMA turns green, sell when HMA turns red
longCondition = hmaValue > hmaValue[1] and hmaValue[1] <= hmaValue[2] // HMA turns up
shortCondition = hmaValue < hmaValue[1] and hmaValue[1] >= hmaValue[2] // HMA turns down
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
//@version=5
strategy("HMA Crossover Strategy", overlay=true)
// Inputs for HMA lengths
fastHmaLength = input.int(10, title="Fast HMA Length", minval=1)
slowHmaLength = input.int(30, title="Slow HMA Length", minval=1)
// Calculate HMAs
fastHma = ta.hma(close, fastHmaLength)
slowHma = ta.hma(close, slowHmaLength)
// Plot the HMAs
plot(fastHma, title="Fast HMA", color=color.blue, linewidth=2)
plot(slowHma, title="Slow HMA", color=color.orange, linewidth=2)
// Crossover conditions (Fast HMA crossing Slow HMA)
longCondition = ta.crossover(fastHma, slowHma)
shortCondition = ta.crossunder(fastHma, slowHma)
// Strategy entries/exits
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
//@version=5
indicator("HMA Support/Resistance", overlay=true)
length = input.int(20, title="HMA Length", minval=1)
hmaValue = ta.hma(close, length)
plot(hmaValue, title="HMA", color=color.blue, linewidth=2)
// Highlight potential support/resistance touches (conceptual - adjust thresholds)
isSupportTouch = hmaValue > close and hmaValue[1] < close[1] and close > hmaValue * 0.995 and close < hmaValue * 1.005 // Price nearing HMA from below and bouncing
isResistanceTouch = hmaValue < close and hmaValue[1] > close[1] and close < hmaValue * 1.005 and close > hmaValue * 0.995 // Price nearing HMA from above and bouncing
plotshape(isSupportTouch, title="Potential Support", location=location.belowbar, color=color.new(color.green, 0), style=shape.circle, size=size.tiny)
plotshape(isResistanceTouch, title="Potential Resistance", location=location.abovebar, color=color.new(color.red, 0), style=shape.circle, size=size.tiny)
To get the most from the Hull Moving Average in Pinescript:
HMA is a balance. While it reduces lag significantly, it's not entirely lag-free. Always be aware of the trade-off, especially on very short timeframes.
The Hull Moving Average (HMA) is a remarkable advancement in the world of technical indicators in Pinescript for TradingView. Its innovative calculation method provides a uniquely smooth line with minimal lag, making it an excellent tool for accurate trend identification and dynamic signal generation. By understanding its construction, applying it thoughtfully within comprehensive trading strategies, and combining it with other analytical tools, you can leverage the HMA to gain a clearer perspective on market direction and improve your trading decisions.
Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pinescript Strategy