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
예시용 — 합성 데이터로, 실시간 호가가 아닙니다.
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 LWMA over the period, and LWMA over half the period
- 2 raw = 2 × fast − slow, which adds the lag estimate back
- 3 Smooth raw with an LWMA over floor(sqrt(period)) — that is the HMA
공식 및 계산 세부 정보 표시
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.
신호
HMA이 제공하는 백테스트 가능한 뚜렷한 신호 — 및 각 신호에 적합한 시장 상황.
Price crossing the line
Builder로 구현 가능Slope turn
Builder로 구현 가능Overshoot fade
고급 로직MT5 구현
MetaTrader 5가 실제로 계산하고 그리는 내용 — 이 페이지의 모든 규칙이 기준으로 삼는 사양입니다.
버퍼
| 인덱스 | 버퍼 | MT5 표시 방식 | 저장 값 |
|---|---|---|---|
| 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. |
플랫폼 참고
가장 잘 작동하는 경우 / 주의해서 사용
어떤 지표도 보편적인 우위를 가지지 않습니다. HMA이 도움이 되는 곳 — 그리고 오해를 일으키는 곳.
가장 잘 작동하는 경우
- 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
주의해서 사용
- 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
HMA 전략 구축
신호를 진입 및 청산 규칙에 연결하고, 컴파일 가능한 MT5 EA를 내보내세요 — 코드 없이.
- One HMA node at period 21, reading the last closed bar
- One LWMA node at the same period 21 — the line the HMA is built from
- Cross up → Close short, then Open Buy · SL 70 / TP 210
- Cross down → Close long, then Open Sell, mirrored
- Both close nodes are wired ahead of the entries so they are emitted first
HMA을 다른 지표와 결합
하나의 지표만으로는 충분하지 않습니다. 이 조합들이 HMA의 취약점을 보완합니다.
HMA + Moving Average
- HMA at 21
- LWMA at 21
- Cross
HMA + DEMA
- HMA at 21
- DEMA at 21
- Cross
No template holds both. Add a DEMA node beside the HMA node, match the periods, and wire both into a Cross.
Builder 열기 →HMA + ADX
- ADX above 25
- HMA cross
- And gate
Add an ADX node with a Compare against 25 and join it to the Cross with an And gate before the entry.
Builder 열기 →매개변수
자신의 통화쌍과 시간 프레임에서 검증할 초기값 — 보장된 설정이 아닙니다.
| 매개변수 | 기본값 | 권장 테스트 범위 | 기능 |
|---|---|---|---|
| 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. |
초기 프리셋
시장 예시
HMA이 작동하는 곳, 실패하는 곳, 그리고 필터가 결과를 어떻게 바꾸는지.
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.
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.
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.