Skip to main content
EMAIndicator

Formulas · Published May 11, 2026 · 6-min read

Hull Moving Average Formula: Step-by-Step HMA Calculation

Alan Hull's HMA formula uses three nested weighted moving averages: a fast WMA over half the period, a slow WMA over the full period, and a final smoothing WMA over the square root of the period. Here is each step in detail with a worked NI

The Hull Moving Average (HMA) is famous for being faster than EMA at trend changes while staying smoother than a similarly fast SMA. Alan Hull achieved this with a clever formula that nests three weighted moving averages — one fast, one slow, and one final smoothing window sized at the square root of the period. This guide walks through every step of the HMA calculation, computes a worked example on NIFTY 50, and explains where each part of the formula comes from.

The formula

For a closing-price series P and a period n, the Hull Moving Average is:

HMA(n) = WMA( 2 × WMA(P, n/2) − WMA(P, n), √n )

Where WMA(series, k) is the standard weighted moving average over k bars (linear weights, sum-of-weights denominator). Three nested WMAs in total:

  1. Fast WMA over half the periodWMA(P, n/2)
  2. Slow WMA over the full periodWMA(P, n)
  3. Smoothing WMA over the square rootWMA(<leading series>, √n)

For a 49-period HMA, that means computing a 24-bar WMA, a 49-bar WMA, subtracting the slow from twice the fast to make a leading series, then smoothing that series with a 7-bar WMA (√49 = 7).

Step 1 — The fast leg

The first ingredient is WMA(P, n/2) — a weighted moving average over half the period. This is the “fast” component because a shorter lookback gives more weight to recent data overall. For HMA(20), this is WMA(10). For HMA(49), this is WMA(24) (or WMA(25) depending on rounding).

Recall from our WMA formula post that WMA assigns linear weights from N (newest) down to 1 (oldest), with denominator N(N+1)/2. So WMA(10) over the last 10 closes has the most recent close at weight 10/55 ≈ 18.2% and the oldest at 1/55 ≈ 1.8%.

This fast WMA, on its own, is responsive but still lags real trend changes by several bars.

Step 2 — The slow leg

The second ingredient is WMA(P, n) — a weighted moving average over the full period. For HMA(20), this is WMA(20); for HMA(49), it is WMA(49). Same linear weighting, but now spread over twice as many bars.

This slow leg lags more than the fast leg. The lag difference between the two is what we exploit in the next step.

Step 3 — The leading series

This is the clever part. Compute:

leading = 2 × WMA(P, n/2) − WMA(P, n)

What does 2 × fast − slow do? Imagine a steadily rising price series. The fast WMA, with its shorter lookback, sits closer to current price. The slow WMA sits further behind. If you take twice the fast and subtract the slow, the result over-corrects forward — landing ahead of where price actually is. In other words, the leading series anticipates direction.

The catch: this “leading” output is also choppier than either WMA on its own. The over-correction picks up short-term noise as well as direction.

For a 5-day worked example on NIFTY 50 — suppose WMA(P, 5) = 24,250 and WMA(P, 2) = 24,360. Then 2 × 24,360 − 24,250 = 48,720 − 24,250 = 24,470. That value of 24,470 is the leading series — it sits above the slow WMA of 24,250 because the recent half-window pulled it forward.

Step 4 — The smoothing

To remove the noise the leading series introduces without re-introducing lag, Alan Hull’s formula applies a final WMA — but over a much shorter window: the square root of the period.

HMA = WMA(leading, √n)

For HMA(49), that final smoothing is WMA(7). For HMA(20), it is WMA(4) (since √20 ≈ 4.47, most platforms floor to 4 or round to 4). For HMA(100), it is WMA(10).

The square root is empirically chosen — Alan Hull experimented with different smoothing window sizes and found the square root struck the best balance between preserving the lead and removing the noise. A shorter window leaves too much choppiness; a longer window restores too much lag.

A worked example — HMA(20) on NIFTY 50 daily

Suppose the last 20 NIFTY 50 daily closes are stored in a column. To compute HMA(20):

  1. Compute WMA(P, 10) — the 10-bar weighted moving average. This requires the most recent 10 closes.
  2. Compute WMA(P, 20) — the 20-bar weighted moving average. This requires all 20 closes.
  3. Compute the leading series: 2 × WMA(P, 10) − WMA(P, 20). One number per bar.
  4. Compute WMA of the leading series over √20 ≈ 4 bars. This requires the leading series to have been computed for the last 4 bars (i.e., you need 23 closes total to produce the first HMA value).

In practice, charting platforms automate all of this — you only see the final HMA line. But knowing the underlying steps tells you why HMA can react faster than a 20-EMA: the leading series in step 3 is what gives HMA its anticipatory edge.

Implementation notes

Integer division. When n/2 or √n is not an integer, platforms typically floor (round down). HMA(20) commonly uses WMA(10), WMA(20), WMA(4). HMA(50) commonly uses WMA(25), WMA(50), WMA(7). HMA(100) uses WMA(50), WMA(100), WMA(10). The exact rounding rarely matters — differences at the third decimal of the final HMA value.

Initialisation. HMA needs a warm-up period equal to the longest WMA in the chain (the full-period WMA), plus a few bars for the final smoothing. For HMA(20) you typically need 24 bars before the first HMA value. For HMA(50), 57 bars. Most platforms display NaN until the first valid HMA can be produced.

Pine Script (TradingView) has a built-in ta.hma:

//@version=5
indicator("Custom HMA", overlay=true)
length = input.int(20, title="HMA Length")
hma_val = ta.hma(close, length)
plot(hma_val, color=color.orange, linewidth=2)

Python / pandas implementation:

import numpy as np
import pandas as pd

def wma(series, n):
    weights = np.arange(1, n + 1)
    return series.rolling(n).apply(lambda x: (x * weights).sum() / weights.sum(), raw=True)

def hma(series, n):
    fast = wma(series, n // 2)
    slow = wma(series, n)
    leading = 2 * fast - slow
    return wma(leading, int(np.sqrt(n)))

Three function calls produce the HMA. No recursion, no smoothing factor — just nested WMAs.

Why √n specifically?

The square root is not arbitrary. Mathematically, the variance reduction from a smoothing window scales linearly with window size, but the lag introduced scales linearly with window size too. To preserve maximum lead while reducing maximum noise, you want a window that grows slower than the period it operates on. The square root achieves this — for HMA(100), the smoothing is only 10 bars, but for HMA(400) the smoothing is 20 bars, scaling sub-linearly with the period.

In practical terms, Alan Hull’s experimentation showed that this scaling produced the smoothest output while preserving the lead. Other smoothing scalings (e.g., logarithmic, fixed-window) either oversmoothed or undersmoothed.

Common HMA periods on Indian indices

  • 9-HMA or 14-HMA on 5-min — intraday scalping
  • 21-HMA on 15-min — intraday bias
  • 49 or 50-HMA on daily — primary trend filter
  • 100-HMA on daily — long-trend confirmation
  • 200-HMA on weekly — multi-quarter trend backdrop

For more on choosing settings, see our Hull Moving Average overview and the upcoming HMA strategy guide.

Putting it together

HMA’s formula is three nested weighted moving averages with a deliberate weight schedule that produces a leading series, then smooths that series over a square-root-sized window. The output is one of the cleanest moving averages available — fast at trend changes, smooth in trends, with a slope that meaningfully signals direction. It is more involved to compute than SMA or EMA, but every charting platform has it built in. Knowing the formula tells you why HMA behaves the way it does and helps you choose the right HMA period for your trading timeframe.

Frequently asked questions

What is the formula for the Hull Moving Average?
HMA(n) = WMA(2 × WMA(P, n/2) − WMA(P, n), √n). It is the weighted moving average of (twice the half-period WMA minus the full-period WMA), smoothed over a square-root window. Three nested WMAs in total.
Why does HMA use a square root?
The square root in the final smoothing window is empirically chosen to balance two goals: keep the lead generated by the half-period subtraction step, and remove the choppiness it introduces. A shorter window would leave too much noise; a longer window would re-introduce lag. Alan Hull's experimentation found √n strikes the right balance for typical equity data.
What does the 2 × WMA(n/2) − WMA(n) part do?
It produces a leading series. The half-period WMA is faster than the full-period WMA, so subtracting the slow from twice the fast yields a value that anticipates where price is heading — at the cost of being noisier. The final √n smoothing then removes that noise without restoring the lag.
Can I calculate HMA without integer division?
Yes. Most platforms use floor(n/2) and floor(√n) when n produces a non-integer half or square root. For example, HMA(20) uses WMA(10), WMA(20), and a final WMA(4) — because √20 ≈ 4.47 and the floor is 4. Some implementations round instead of floor; the difference is negligible after a few bars.
Is HMA the same as Alan Hull moving average?
Yes — HMA stands for Hull Moving Average, named after its inventor Alan Hull, an Australian trader and author. He published the formula in 2005 and has used the abbreviation HMA in subsequent writing. Some platforms label it 'Hull MA' or 'AHMA' but the calculation is identical.

More in Moving Averages: The Complete Guide for NIFTY & BANKNIFTY Traders

Related on emaindicator.com