Skip to main content

HMA

Source

https://github.com/quadcode-tech/quadcodescript-library/blob/master/averages/ma_hma.lua

Syntax Format

hma(series, period)

Overview

HMA (Hull Moving Average) belongs to the MA family, and aims at smoothing the asset price movements. HMA might have more advantages compared to SMA and EMA in regard to being more responsive to the price changes.

The function returns the Hull moving average of source for the period bars.

Parameters

ParameterTypePurpose
seriesseriesInput series, taken into calculation
periodnumericMA (moving average) period

Returns: series.

Example

instrument { name = "Hull Moving Average", short_name = "HMA", overlay = true, icon="indicators:MA" }

period = input (9, "period", input.integer, 1)
source = input (1, "source", input.string_selection, inputs.titles_overlay)

input_group {
"HMA Line",
color = input { default = "#B42EFF", type = input.color },
width = input { default = 1, type = input.line_width}
}

local sourceSeries = inputs [source]

plot (hma (sourceSeries, period), "HMA", color, width)

Formula

The formula for calculating HMA is:

image.png

The Weighted Moving Average values are used for the calculation: first, half of the period is calculated, then the full period value is calculated. Then, the second WMA value is subtracted from the first one, the final operation is to use a square root of n, where n is a period back value.