Tùy chỉnh & cộng đồng TrendMoving AverageNot MT5 Built-in Có trong Builder

HMA

The Hull Moving Average recombines two weighted averages so the line keeps up with price instead of trailing it. MetaTrader 5 does not ship it — there is no iHMA — and the lag it removes is not all of the lag: at period 21 a straight trend still leaves the line 0.33 bars behind, and raising the period by one reduces that figure as often as it raises it.

Period
21 — half 10, smoothing 4
Residual lag at 21
0.33 bars (LWMA: 6.67)
Overshoot on a 10-point step
+2.85
HMA 21 and LWMA 21 — same period, different constructionZero — the cross, and the only level in the flowHMA 21 minus LWMA 21 (derived — MT5 publishes no HMA buffer)

Minh họa — dữ liệu tổng hợp, không phải giá thực.

What HMA tells you

Every moving average is late, and the Hull average is an attempt to subtract that lateness rather than live with it. Take a weighted average over the full period, take another over half of it, and the difference between them is an estimate of how far behind the slow one is; double the fast one, subtract the slow one, and you have added that estimate back. The result is jagged, so a third weighted average — over the square root of the period — smooths it. What comes out keeps up with price remarkably well, and the measurements on this page are mostly about what that costs. Two things are worth knowing before the settings. The lag is reduced, not removed: at period 21 the line still sits a third of a bar behind a straight trend, and the exact figure follows a formula with two floors in it, so it moves in steps and is not monotonic in the period. And the line is not an average at all in the strict sense — it can and does print values no bar ever traded at.

  • Not an MT5 built-in: the Builder creates two LWMA handles and folds the last stage itself
  • The residual lag is a formula, not zero — and raising the period can lower it
  • The lead is paid for in overshoot and in roughly 1.8× the bar-to-bar movement
  1. 1 LWMA over the period, and LWMA over half the period
  2. 2 raw = 2 × fast − slow, which adds the lag estimate back
  3. 3 Smooth raw with an LWMA over floor(sqrt(period)) — that is the HMA
Hiển thị công thức & chi tiết tính toán

MetaTrader 5 has no Hull average, so there is no source file to quote. What the Builder generates is Alan Hull’s definition, with the two lengths derived from the one period:

half = floor(period / 2)          <- 10 when period is 21
p    = floor(sqrt(period))        <- 4  when period is 21

raw[i] = 2 * LWMA(price, half)[i] - LWMA(price, period)[i]
HMA[i] = LWMA(raw, p)[i]

The first two are ordinary iMA handles in MODE_LWMA. The third is not: it has to smooth raw, a series no indicator publishes. MQL5 would allow it in principle — iMA accepts another indicator’s handle where an applied price normally goes, which compiles clean — but there is no handle for a difference of two indicators to hand over. So the generated EA copies both buffers and folds the last stage itself:

_hmP = floor(sqrt(HMA_Period))                       <- the smoothing length
_hmN = _hmP + 1                                      <- +1 so _prev exists for a Cross
sum  = Σ (2*fast[j+k] - slow[j+k]) * (_hmP - k)      <- newest bar carries the largest weight
HMA  = sum / (_hmP * (_hmP + 1) / 2)

The weights run the other way from the array: k = 0 is the most recent bar and carries weight _hmP. Reversing them still compiles and still draws a plausible line, but on a linear series the correct orientation leaves the line 0.33 bars behind price at period 21 and the reversed one leaves it 1.33 behind. The extra bar is (p−1)/3 — the distance the centre of mass travels when p linear weights are flipped — and it matched at every period tested: a third of a bar at period 4, two thirds at 9 and 14, one bar at 21, two at 49 and 55, three at 100.

That gives the lag its closed form. An LWMA of length m trails a straight trend by (m−1)/3 bars, so

lag(HMA) = 2*(half-1)/3 - (period-1)/3 + (p-1)/3
         = (2*half - period + p - 2) / 3

which is 0.33 bars at period 21 against 6.67 for the LWMA of the same length. Both floors sit inside that expression, which is why the result steps rather than scales, and why an odd period — losing half a bar in floor(period/2) — can come out faster than the even one above it.

It is worth knowing that the same lag has a second, opposite answer. Hull removes it arithmetically so the line can be traded in real time. The textbook Detrended Price Oscillator leaves the lag alone and moves the price back to meet it — by N/2+1 bars, which is where an N-bar window’s centre actually sits. Measured against a known 20-bar cycle, that shifted reading tracks the wave almost perfectly but lands 11 bars behind today’s candle: precise for describing a cycle already past, unusable for deciding to trade now.

Tín hiệu

Các tín hiệu có thể backtest của HMA — và điều kiện thị trường phù hợp với từng tín hiệu.

Cross of the LWMA it is built from

Sẵn sàng trong Builder
Điều kiện
HMA crosses the LWMA of the same period
Điều kiện tốt nhất
Trending
Sử dụng thông thường
The template's entry — a sign change of the lag correction rather than a fast-slow event

Price crossing the line

Sẵn sàng trong Builder
Điều kiện
Close crosses the HMA
Điều kiện tốt nhất
Trending
Sử dụng thông thường
The classic MA use. Fires earlier than with an LWMA, and more often

Slope turn

Sẵn sàng trong Builder
Điều kiện
The HMA turns up or down against its own previous value
Điều kiện tốt nhất
Trending
Sử dụng thông thường
Two HMA nodes at shift 1 and 2 into a Compare — the Builder has no slope output for this node

Overshoot fade

Logic nâng cao
Điều kiện
The line runs past the extreme of the recent bars and turns back
Điều kiện tốt nhất
Ranging
Sử dụng thông thường
Described often; needs the line compared with a range it is not built from, so it is several nodes rather than a comparison

Triển khai trong MT5

Những gì MetaTrader 5 thực sự tính và vẽ — cơ sở tham chiếu cho mọi quy tắc trên trang này.

Bộ đệm

Chỉ số Bộ đệm MT5 vẽ dưới dạng Chứa gì
0 MAIN_LINE Line There is no HMA buffer to read, because there is no HMA indicator in MT5. The two handles the generated EA creates are both iMA in MODE_LWMA — one at half the period, one at the full period — and index 0 of each is that weighted average. The subtraction and the final smoothing happen in the EA, so the line you see on this page is never published by the terminal to anything.

Ghi chú nền tảng

Hoạt động tốt nhất / sử dụng cẩn thận

Không có chỉ báo nào có lợi thế toàn diện. Đây là nơi HMA hỗ trợ — và nơi nó gây hiểu lầm.

Hoạt động tốt nhất

  • Trending instruments and timeframes, where the earlier turn is worth the extra crossings
  • As the fast line in a pair, where the slow side supplies the confirmation it lacks
  • Settings you have measured, because the residual lag steps rather than scales
  • Flows where an early exit is more valuable than a rare one

Sử dụng cẩn thận

  • Reading it as a zero-lag line — at period 21 it is 0.33 bars behind, and at 100 it is 2.67
  • Assuming a longer period is always a slower line; raising it by one lowers the lag in 93 of 198 steps
  • Ranges, where the same responsiveness that finds the turn early also finds every false one
  • Treating a value as a price level that traded — a 10-point step takes the line to 112.85

Xây dựng chiến lược HMA

Kết nối tín hiệu vào quy tắc vào lệnh và thoát lệnh, sau đó xuất EA MT5 có thể biên dịch — không cần code.

  1. One HMA node at period 21, reading the last closed bar
  2. One LWMA node at the same period 21 — the line the HMA is built from
  3. Cross up → Close short, then Open Buy · SL 70 / TP 210
  4. Cross down → Close long, then Open Sell, mirrored
  5. Both close nodes are wired ahead of the entries so they are emitted first

Kết hợp HMA với các chỉ báo khác

Một chỉ báo hiếm khi đứng một mình. Các cặp kết hợp này bù đắp điểm mù của HMA.

HMA + Moving Average

  1. HMA at 21
  2. LWMA at 21
  3. Cross
Lý do
This is the pairing the template makes, and it is a deliberate one: the LWMA is not a second opinion but the material the HMA is built from. Because both lines carry the same period, the distance between them is not 'fast versus slow' — it is the lag correction itself, and the cross is that correction changing sign. Set the MA node to MODE_LWMA and match the period, or the comparison stops meaning that. Measured on a straight trend the two sit 6.33 bars apart in responsiveness, which is the entire content of the signal
Điều kiện tốt nhất
Trending
Xây dựng chiến lược này →

HMA + DEMA

  1. HMA at 21
  2. DEMA at 21
  3. Cross
Lý do
The other lag-correcting average in the palette, and worth opening beside this one because it makes the same trade with different materials — EMAs and a doubling instead of LWMAs and a doubling, then no third stage. Both leave the range of their own window, which is what makes them not averages in the strict sense. Reading the two pages together is the cheapest way to see that the overshoot is structural to the method rather than a quirk of one formula
Điều kiện tốt nhất
Trending

No template holds both. Add a DEMA node beside the HMA node, match the periods, and wire both into a Cross.

Mở Builder →

HMA + ADX

  1. ADX above 25
  2. HMA cross
  3. And gate
Lý do
The measured weakness of this line is what it does in a range: it moves 1.78 times as much bar to bar as its own LWMA, so crossings multiply exactly where they are worth least. ADX is the standard answer — require a trend reading before the cross is allowed to act. This does not make the cross more accurate; it removes the regime in which the extra sensitivity is a liability rather than an edge
Điều kiện tốt nhất
Trending

Add an ADX node with a Compare against 25 and join it to the Cross with an And gate before the entry.

Mở Builder →

Tham số

Giá trị ban đầu để xác nhận trên cặp tiền và khung thời gian của bạn — không phải cài đặt được đảm bảo.

Tham số Mặc định Khoảng thử nghiệm đề xuất Chức năng
Period 21 2–200 The full LWMA length. Everything else is derived: the fast stage is floor(period/2) and the smoothing stage is floor(sqrt(period)), so 21 becomes 10 and 4. Because both are floors, the responsiveness moves in steps rather than smoothly — measured across every period from 2 to 200, raising the period by one *reduced* the residual lag in 93 of the 198 steps. Period 21 sits 0.33 bars behind a straight trend and period 22 sits 0.67 behind, so the longer setting is the faster one of that pair.
Applied price Close Close / Open / High / Low / Median / Typical / Weighted Handed to both iMA calls, so the two stages always agree. Median or Typical make the line marginally steadier on instruments with long wicks, at the cost of reacting to a level no trade closed at. There is no separate price for the smoothing stage, because that stage runs on the difference rather than on prices.
Shift 1 0–100 Which bar the node reads. The template uses 1 so decisions are made on a closed bar. Shift 0 matters more here than for a slow average: the fast stage has half the period, so an unfinished bar moves the line several times more than it would move an LWMA of the same nominal length.
Timeframe Current Current / M1–MN1 Which timeframe both LWMA handles are created on. The lag figures on this page are in bars, so they carry across timeframes unchanged — 0.33 bars is 20 seconds on M1 and 80 minutes on H4.
Half period (derived) floor(period / 2) Not exposed, and the reason odd periods behave differently: at 21 the fast stage is 10, so 2×half − period is −1 rather than 0, and that missing half bar is subtracted from the lag. It is why odd periods average 2.01 bars of lag over 2–200 while even periods average 2.34.
Smoothing period (derived) floor(sqrt(period)) The last stage, and the one that decides how rough the line is. It changes only at square numbers, so periods 16 through 24 all smooth with 4 — which is why the lag inside that band is set by the half-period floor alone.

Cài đặt sẵn ban đầu

Template 21 / Close / shift 1 Half 10, smoothing 4, and a residual lag of a third of a bar
Faster pair 9 and 21 Period 9 is one of the settings where the residual lag measures exactly zero
Slower filter 55 1.33 bars behind — still less than a fifth of the LWMA's 18 at the same period

Ví dụ thị trường

Nơi HMA hoạt động, nơi nó thất bại, và bộ lọc thay đổi kết quả như thế nào.

Thành công

The turn caught six bars early

A trend rolls over and the HMA crosses its own LWMA well before the slow line has turned at all. The gap between the two crossings is the lag difference this page measures — six bars and a third at period 21 — and it is the entire reason for using the line.

Thất bại

The range that crossed four times

The same responsiveness inside a sideways stretch. Bar-to-bar the line moves 1.78 times as much as its LWMA, so every small swing produces a crossing, and the stop distance is what decides how much each one costs.

Đã lọc

The spike the line ran past

A single sharp bar sends the correction term well beyond the candles — the same behaviour that produces 112.85 on a 10-point step. Price does not follow, and the line comes back on its own.

FAQ

Is HMA a built-in MetaTrader 5 indicator?
No. MT5's moving-average family is SMA, EMA, SMMA and LWMA — there is no iHMA. The Builder's node creates two iMA handles in MODE_LWMA, one at half the period and one at the full period, and computes the final smoothing stage inside the generated EA. Nothing needs to be installed in the terminal, and no custom .ex5 is involved.
Does the HMA really have zero lag?
No, and the figure is measurable. On a straight trend the line sits (2·floor(n/2) − n + floor(sqrt(n)) − 2)/3 bars behind price: 0.33 bars at period 21, 1.33 at 55, 2.67 at 100. It is exactly zero only at a handful of short periods — 4, 6, 8, 9, 11, 13, 15 — and it is genuinely negative at 2, 3, 5 and 7, where the line leads. The formula was checked against synthetic linear series for every period from 2 to 200 without a single mismatch.
How much faster is it than the LWMA it is built from?
At the same period 21, 6.33 bars on a straight trend — 6.67 against 0.33. On a step from 100 to 110 it reaches 95% of the new level in 6 bars against the LWMA's 17 and an EMA's 32. That difference is what the template's cross detects, which is why both lines in it carry the same period.
Why does a longer period sometimes react faster?
Because both derived lengths are floors. An odd period loses half a bar in floor(period/2), and that missing half is subtracted from the lag, so 21 (0.33 bars) is faster than 22 (0.67). Measured over every period from 2 to 200, raising the period by one reduced the lag in 93 of the 198 steps, and odd periods averaged 2.01 bars against 2.34 for even ones.
Can the HMA show a price that never traded?
Yes, and it is not a defect — it follows from the formula. A true moving average is a convex combination of the prices in its window and therefore cannot leave their range, but 2×LWMA(half) − LWMA(full) can. On a 10-point step the line reaches 112.85, 28.5% past the new level, and the figure is almost the same at period 55 (112.83). Anything that treats the line as a level — a stop, a target, a Compare against price — should be built with that in mind.
Why does it whipsaw in ranges?
The correction that removes the lag also amplifies recent movement. Measured on a random walk over 2,500 bars, the HMA's average bar-to-bar change was 1.78 times the LWMA's at period 21 and 1.72 times at 55. In a trend that responsiveness is the point; in a range it produces crossings at every small swing, which is why the usual remedy is a regime filter such as ADX rather than a longer period.
Which period should I use?
The template uses 21 because it is the common default and its residual lag is among the lowest in its neighbourhood. Do not read the period as a smooth dial: the smoothing stage is 4 for everything from 16 to 24, so inside that band only the half-period floor moves the line, and the lag surface is jagged. Optimising the period on a single data set will find that jaggedness before it finds an edge.
Can I build this without coding?
Yes. The template is an HMA node and a Moving Average node set to MODE_LWMA at the same period, two Cross nodes for the two directions, two Close nodes wired ahead of the entries, and Open Buy / Open Sell with a fixed lot. The period, applied price, stop distances, lot size and maximum spread are all set in the Builder; the compiled EA exposes the stop distances, lot, magic number, slippage, once-per-bar and maximum spread as inputs.

Glossary

Thuật ngữ chính