All indicators
Trend / Price pane

Hull Moving Average

Alan Hull's moving average: a smooth line with very little lag, built from weighted averages, drawn on the candles.

  • HMA
  • Built into Spectral
  • Updates every tick
  • hull
  • hma
  • moving average
  • low lag
  • trend

By Spectral · v1.0.0

MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.

Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Hull Moving Average on a Spectral chart
Spectral chart with sample market data, default settings.

Overview

The Hull Moving Average, published by Alan Hull in 2005, aims to be both smooth and fast. It takes a weighted moving average (WMA) over half the length, doubles it, subtracts the WMA over the full length, and smooths the result with a WMA over the square root of the length.

The doubling pushes the line ahead to offset the lag of the full average, and the short final smoothing removes the noise this adds. On a steady straight-line trend the Hull average stays within a fraction of a bar of price instead of trailing behind it.

How to read it

Traders mainly read the slope: a Hull line turning up marks a shift to rising prices, turning down a shift to falling ones, and these turns come earlier than on an SMA or EMA of the same length. Price holding above a rising Hull line describes a healthy up-move.

The speed has a cost: after a sharp move the line overshoots, so it can run beyond price for a few bars before it turns, and in sideways markets it turns often. It describes direction; it is not a support level as reliably as slower averages.

Settings and limitations

Length defaults to 9 bars, as on most platforms; the presets add 21, 55 and 200 for swing and trend views. The half length and the square-root length are rounded down, so lengths 16 and 17 both smooth over 4 bars.

The first value appears on bar Length + square-root length - 1, for example on bar 11 with the default length.

Notes

Alan Hull's formula with the half length and the square-root length rounded down, as in TradingView's Hull Moving Average script. Some implementations round the square root to the nearest whole number instead, which changes the final smoothing for a few lengths (21 smooths over 4 bars here, over 5 there). The Moving Average indicator offers the same line as its HMA type, next to the other common averages.

Settings

Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.

SettingTypeDefaultRange or optionsWhat it does
LengthWhole number92 – 1000Number of bars the average covers. Longer lengths are smoother; the Hull average stays responsive even at long lengths.
SourcePrice sourcecloseopen, high, low, close, hlc3Price the average is calculated from.

Presets

Each preset is its own entry in the Indicators toolbox, with these settings changed.

Toolbox entryShort nameSettings
Hull MA 21HMA 21Length: 21
Hull MA 55HMA 55Length: 55
Hull MA 200HMA 200Length: 200

What it draws

Lines

  • HMAsolid · 1 px · primary#7FB5A0

Source

Save it as hull-ma.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.

// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
  schemaVersion: 2,
  id: 'hull-ma',
  name: 'Hull Moving Average',
  shortName: 'HMA',
  version: '1.0.0',
  author: 'Spectral',
  description: 'Alan Hull\'s moving average: a smooth line with very little lag, built from weighted averages, drawn on the candles.',
  pane: 'price',
  live: { lookback: '2*length' },
  inputs: {
    length: { type: 'integer', label: 'Length', default: 9, min: 2, max: 1000, description: 'Number of bars the average covers. Longer lengths are smoother; the Hull average stays responsive even at long lengths.' },
    source: { type: 'source', label: 'Source', default: 'close', description: 'Price the average is calculated from.' },
  },
  plots: {
    hull: { label: 'HMA', color: '#7FB5A0', lineWidth: 1, primary: true },
  },
  presets: [
    { id: 'hma-21', name: 'Hull MA 21', shortName: 'HMA 21', inputs: { length: 21 } },
    { id: 'hma-55', name: 'Hull MA 55', shortName: 'HMA 55', inputs: { length: 55 } },
    { id: 'hma-200', name: 'Hull MA 200', shortName: 'HMA 200', inputs: { length: 200 } },
  ],
  docs: {
    overview: 'The Hull Moving Average, published by Alan Hull in 2005, aims to be both smooth and fast. It takes a weighted moving average (WMA) over half the length, doubles it, subtracts the WMA over the full length, and smooths the result with a WMA over the square root of the length.\n\nThe doubling pushes the line ahead to offset the lag of the full average, and the short final smoothing removes the noise this adds. On a steady straight-line trend the Hull average stays within a fraction of a bar of price instead of trailing behind it.',
    howToRead: 'Traders mainly read the slope: a Hull line turning up marks a shift to rising prices, turning down a shift to falling ones, and these turns come earlier than on an SMA or EMA of the same length. Price holding above a rising Hull line describes a healthy up-move.\n\nThe speed has a cost: after a sharp move the line overshoots, so it can run beyond price for a few bars before it turns, and in sideways markets it turns often. It describes direction; it is not a support level as reliably as slower averages.',
    settings: 'Length defaults to 9 bars, as on most platforms; the presets add 21, 55 and 200 for swing and trend views. The half length and the square-root length are rounded down, so lengths 16 and 17 both smooth over 4 bars.\n\nThe first value appears on bar Length + square-root length - 1, for example on bar 11 with the default length.',
    notes: 'Alan Hull\'s formula with the half length and the square-root length rounded down, as in TradingView\'s Hull Moving Average script. Some implementations round the square root to the nearest whole number instead, which changes the final smoothing for a few lengths (21 smooths over 4 bars here, over 5 there). The Moving Average indicator offers the same line as its HMA type, next to the other common averages.',
  },
  calculate(ctx) {
    const { bars, inputs, ta } = ctx;
    const values = ta.source(bars, inputs.source);
    const length = inputs.length;
    const half = ta.wma(values, Math.max(1, Math.floor(length / 2)));
    const full = ta.wma(values, length);
    const raw = full.map((value, index) => (value === null || half[index] === null ? null : 2 * half[index] - value));
    return { plots: { hull: ta.wma(raw, Math.max(1, Math.floor(Math.sqrt(length)))) } };
  },
};

Adapt it with an LLM

Paste this into your assistant and replace the second-to-last line with the change you want.

Start from this Spectral custom indicator: https://spectral.trade/indicators/hull-ma.js
Format reference: https://spectral.trade/docs/custom-indicators.llm.md
Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match.
Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow.
Change I want: <describe the change>
Answer with the complete file in one code block, ready to save as <id>.js.