YoForex AI educational guides
Hull moving average: the formula, the lag trade-off and the MT5 setup
The Hull moving average (HMA) is built from weighted moving averages, with a final weighted average over the square root of the period. Alan Hull published the method to reduce lag while keeping the line smooth. MetaQuotes lists four moving average types for MT5, not the HMA, so an HMA on MT5 would need a custom indicator.
Published · Updated · By YoForex AI Editorial Team
What is the Hull moving average?
The Hull moving average (HMA) is a moving average that Alan Hull describes on his own page, titled “The Hull Moving Average.” He writes there that it came out of his work in 2005 on the problem of lag in moving averages. It is built from weighted moving averages (WMAs) rather than a simple mean of closing prices. On that page, Alan Hull writes: “In fact the HMA almost eliminates lag altogether and manages to improve smoothing at the same time.” That is the author's claim, and this guide has not tested it.
The HMA indicator is a moving average, like the simple moving average (SMA) and the exponential moving average (EMA). It is meant to follow price more closely than a standard average of the same length. Whether it does so usefully on your instrument is a question for testing, not something the formula settles.
How is the HMA calculated?
The formula is HMA = WMA(2 × WMA(n/2) − WMA(n), √n). Read it from the inside out. Calculate a WMA over half the period and double it. Subtract a WMA over the full period. Then smooth that difference series with a WMA over the square root of the period.
- Calculate a WMA over n/2 periods, and multiply the result by 2.
- Calculate a WMA over n periods.
- For each bar, subtract the result of step 2 from step 1. This gives a raw difference series.
- Calculate a WMA over √n periods of the raw difference series. The result is the HMA line.
Alan Hull's page writes the same calculation in its own notation, and it wraps the half period and the square root in Integer(), which makes each of them a whole number of bars. The page does not spell out in words how a non-whole result is handled, so check how your code rounds it before you compare two HMA lines.
A WMA gives the newer prices more value. MetaQuotes describes its weighted moving average with the words “the latest data is of more value than more early data.” The HMA is built from weighted averages, not an equal-weight mean, so its construction differs from a plain SMA of the same length.
How does an HMA differ from an SMA on the same prices? (hypothetical example)
The example uses seven made-up closing prices: 100, 102, 101, 105, 108, 107 and 110. The numbers are invented for this example and belong to no instrument. It uses n = 4, so n/2 = 2 and √n = 2. Both are whole numbers, which avoids the rounding question. The WMA here uses linear weights from 1 to n, with the newest close carrying weight n. That is the convention for this example only, not a claim about any platform.
| Day | Close | SMA(4) | HMA(4) |
|---|---|---|---|
| Day 4 | 105.00 | 102.00 | not yet defined |
| Day 5 | 108.00 | 104.00 | 107.48 |
| Day 6 | 107.00 | 105.25 | 108.54 |
| Day 7 | 110.00 | 107.50 | 109.32 |
The HMA needs two raw difference values before its final average can be calculated, so its first value appears on day 5. On day 5, the two WMAs are 107.00 over 2 periods and 105.10 over 4 periods. The raw difference is 2 × 107.00 − 105.10 = 108.90. The HMA is the WMA over 2 periods of the raw values from day 4 and day 5, which is (104.63 × 1 + 108.90 × 2) ÷ 3 = 107.48.
On day 7 the close is 110, the SMA(4) is 107.50 and the HMA(4) is 109.32. The HMA sits closer to the latest close in this series. That follows from the calculation on these made-up numbers. It is not evidence that an HMA will be more useful on a real chart.
Why is the HMA meant to reduce lag, and what does it cost?
Lag is the delay between a change in price and the moment an average turns. A simple average of n closes can change only as its window fills with new prices. The HMA's construction aims at less lag, because its final average works on a difference between a faster and a slower weighted average. Alan Hull's page makes the same claim. Whether the lag is reduced on your instrument is something you measure, not something the formula proves.
The cost is the same one that applies to any faster average. A line that turns sooner also reacts to short noise, and a rule built on its turns can trade more often. The EMA vs SMA guide covers the weighting logic that the simple and exponential averages share, and the SuperTrend guide covers another trend-following line.
Is the Hull moving average built into MT5?
The MetaQuotes Moving Average help page says there are four types of moving average: simple, exponential, smoothed and linear weighted. It does not mention Hull or HMA. So the HMA is not in the MetaQuotes Moving Average methods list. That is a statement about that list, not about every indicator that may exist for MT5.
The MQL5 iMA function reference describes the ma_method parameter as the smoothing type and says it takes one of the ENUM_MA_METHOD values. Its example uses MODE_SMA. The reference does not list an HMA value in the text this guide reviewed.
To run an HMA on MT5 you would need a custom indicator. Whoever writes or sells that indicator defines its inputs, its period handling and its output. This guide does not name or assess any such indicator. Before you rely on one, read its code and check three things: whether the WMA steps match the formula above, how the square root is rounded, and what default period it uses.
Alan Hull's page sets the period input of its MetaStock code to 20. That is a default in his code, not a recommended setting. Test the period on your own pair and timeframe, and state it with the rule. If an Expert Advisor uses an HMA, ask for the formula, the period and the rounding before you accept its entry logic. The EA evaluation guide lists the questions to ask, and the forex expert advisor guide explains what an EA can and cannot do with rules like these.
How do you add an HMA to MT5 as a custom indicator?
Because the HMA is not in the MetaQuotes Moving Average methods list, the code you attach is the only definition of the line on your chart. MetaQuotes' help on creating an indicator says that all indicators are stored in the /MQL5/Indicators folder of the platform, and that you can create one from the Navigator. The steps below follow that help.
- In the Navigator, open the Indicators section, right-click and choose Create in MetaEditor. Write or paste the HMA code, then check it against the formula in this guide: the WMA steps, the rounding of the square root and the default period.
- Press F7 to compile. MetaQuotes says this creates an executable .EX5 file.
- Drag the compiled indicator from the Navigator onto the chart. The MetaQuotes Technical Indicators help calls this the most convenient way to apply an indicator.
- Set the parameters when you apply the indicator, or change them later from the chart's indicator list.
The MetaQuotes help on creating an Expert Advisor or an Indicator covers the Navigator and the folder. The MetaQuotes Technical Indicators help covers applying indicators to a chart. Neither page names an HMA, so the code and its author are what you need to check.
What can the Hull moving average not tell you?
The EMA vs SMA guide covers the limits of moving average crossovers. This section lists the limits that are specific to the HMA:
- The lag reduction is the author's claim. This guide has not shown it on any instrument. Measure the lag on your own data.
- Square-root rounding changes the line. The final average uses the square root of n. For periods that are not perfect squares, your code's rounding changes the result, so check it.
- Code may differ from the formula. A custom indicator can differ in rounding, starting values or the number of bars used.
- The period is a test choice. The 20 in Alan Hull's MetaStock code is an input default in his code. Test your own.
Before you trust an HMA rule, record its results on data you did not use to pick the period. The paper trading guide explains what that record can show.
Risk warning. You can lose more than you deposit, depending on your broker and country. Forex trades can use leverage, which can make losses grow quickly. A line that turns on short moves can produce several small losses in a sideways market, and a backtest cannot promise the next result. Check the rules that apply to you with your own regulator.
Key takeaways
- The HMA is WMA(2 × WMA(n/2) − WMA(n), √n), a formula Alan Hull published with a claim to reduce lag that this guide has not tested.
- The HMA is not in the MetaQuotes Moving Average methods list, so MT5 use needs a custom indicator whose code you should read.
- In the hypothetical example, the HMA sits closer to the latest close than the SMA. That is a property of the arithmetic on made-up numbers, not a forecast.
- Faster lines also react to noise. Test the lag reduction and the whipsaw cost on your own data, with costs included.
- State the formula, the period and the rounding for any HMA rule before you judge it.
Frequently asked questions
What does HMA stand for?
HMA stands for Hull moving average. It is the short name used in this guide and on Alan Hull's page.
Who created the Hull moving average?
Alan Hull. On his own page, titled “The Hull Moving Average,” he writes that the indicator came out of his work in 2005 on the problem of lag in moving averages.
Does MT5 include an HMA indicator?
It is not in the MetaQuotes Moving Average methods list, which names simple, exponential, smoothed and linear weighted averages. To use an HMA on MT5 you would need a custom indicator, so read its code before you rely on it.
Is an HMA better than an EMA?
Neither is better in general. The HMA is designed to reduce lag, and the EMA is a simpler weighting of recent closes. Each turns on noise as well as on real moves. Compare them on your own pair and timeframe, with the same rule and costs, before you choose one.
Which period should I use for an HMA?
No period is correct for every market. The period default in Alan Hull's MetaStock code is 20, and that is not a recommendation. Pick a period for a reason you can state, and test it forward before you rely on it.
Sources and verification
Primary-source links used for the platform behavior and risk statements in this guide. Sources reviewed 10 November 2026.
- Alan Hull: The Hull Moving Average · Reviewed
- MetaQuotes: How to Create an Expert Advisor or an Indicator · Reviewed
- MetaQuotes: Technical Indicators · Reviewed
- MetaQuotes: Moving Average · Reviewed
- MetaQuotes: iMA · Reviewed