Fix the experiment before choosing an average
Use N = 16, closing prices and no plot offset for both methods. Each of the three independent synthetic samples starts after 32 closes of 100; seed EMA at 100 and reset both methods before the next sample. These are calculated responses, not market observations or backtests. Bar 1 is the first new close after initialization. Calculate with full precision and round only the displayed results to three decimals.
- Define an up cross as current close > current average and previous close ≤ previous average. A down cross reverses both inequalities. Equality on the current bar produces no signal. Read each condition only after that bar closes.
- Count the first up cross separately from later direction changes. All three samples start with price equal to both averages at bar 0.
- The cross rule is a measurement probe, not a recommended HMA trading system. Alan Hull describes turning points as a possible use and cautions against crossover signals in his original explanation.
| Sample | Closes on bars 1 through 24 | Question |
|---|
| Step | 110 on every bar | How quickly does the line reach the new level, and does it overshoot? |
| One-way trend | 102, 104, 106, …, 148; close = 100 + 2 × bar | How far behind the rising price does each line remain? |
| Sideways | 102, 98 repeated 12 times | Does a smaller oscillation remove repeated price crosses? |
The minimum arithmetic needed to reproduce the test
For a WMA of length m, give the newest observation weight m, the previous one m − 1, down to 1 for the oldest, then divide by m(m + 1)/2. Compute R = 2 × WMA(close, 8) − WMA(close, 16), then HMA = WMA(R, 4). Update EMA = (2/17) × close + (15/17) × previous EMA. Sixteen makes both N/2 and the square root of N integers, so this experiment has no length-rounding ambiguity.
- On the first step bar, WMA(8) = 100 + 10 × 8/36 = 102.222222 and WMA(16) = 100 + 10 × 16/136 = 101.176471. R is 103.267974. With the three earlier R values at 100, HMA = 100 + (4/10) × 3.267974 = 101.307190. EMA is 101.176471.
- HMA needs enough observations for both inner windows and its final smoothing. With these lengths, 19 consecutive source observations provide the first complete HMA window. EMA also needs a seed; matching the visible start date alone does not match its history.
- For other lengths, document how each implementation converts N/2 and √N into integer windows. Do not silently round differently across platforms. Handle missing observations explicitly rather than treating them as zero.
Step response: HMA arrives sooner and goes past the target
Price jumps from 100 to 110 and stays there. Define response speed as the first completed bar on which the average reaches 109, or 90% of the ten-unit step. HMA reaches that threshold on bar 5; EMA reaches it on bar 19. Reaching a threshold and settling at the final price are different measurements.
- HMA peaks at 112.512255 on bar 8. Overshoot relative to the input step is (112.512255 − 110) / (110 − 100) × 100 = 25.123%. This is a filter-response percentage, not a return.
- Both methods give an up cross on bar 1. HMA then gives a down cross on bar 6 even though price has not fallen. EMA remains below 110 throughout these 24 bars. The HMA exit would be caused by the moving line passing price.
- HMA equals 110 from bar 19 onward because every observation in its finite window is then 110. EMA approaches 110 from below: EMA at bar t = 110 − 10 × (15/17)^t. Its positive weighting prevents overshoot in this constant-step experiment.
| Bar | Close | HMA (16) | EMA (16) |
|---|
| 1 | 110 | 101.307 | 101.176 |
| 4 | 110 | 108.117 | 103.939 |
| 5 | 110 | 109.939 | 104.652 |
| 6 | 110 | 111.279 | 105.281 |
| 8 | 110 | 112.512 | 106.326 |
| 12 | 110 | 111.140 | 107.773 |
| 16 | 110 | 110.110 | 108.650 |
| 19 | 110 | 110.000 | 109.073 |
| 24 | 110 | 110.000 | 109.504 |
One-way trend: less tracking error, the same first cross
Reset the initialization, then raise every close by two units. HMA moves closer to this sustained trend, but both methods produce their first up cross on bar 1 and no down cross during bars 1 through 24. Less distance from price does not move the entry earlier under this particular rule.
- At bar 24, close minus HMA is 1.333333; close minus EMA is 14.256112. Dividing by the two-unit rise gives equivalent distances of 0.667 and 7.128 bars along this ramp. These are ramp-specific measurements, not universal delays for arbitrary markets.
- A rule based on the slope of an average measures something different from a price cross. Choose that rule before comparing the methods and repeat all three samples for it; do not report the best-looking rule from each sample as one strategy.
| Bar | Close | HMA (16) | EMA (16) |
|---|
| 1 | 102 | 100.261 | 100.235 |
| 4 | 108 | 103.728 | 102.092 |
| 8 | 116 | 112.901 | 106.511 |
| 12 | 124 | 122.334 | 112.340 |
| 19 | 138 | 136.667 | 124.391 |
| 24 | 148 | 146.667 | 133.744 |
Sideways prices: less line movement, just as many crosses
Reset again, then alternate closes between 102 and 98 for 24 bars. Each close is above both averages on odd bars and below both on even bars. Both methods therefore give one initial up cross and 23 later direction changes. Waiting for closed candles cannot remove this pattern because every value in the experiment is already a completed close.
- Once its window contains only alternating prices, HMA oscillates by about ±0.065359 around 100. EMA approaches an oscillation of ±0.125. HMA is smoother on this particular input, while the crossing count is identical.
- A long-only enter-on-up, exit-on-down interpretation would create 12 signal pairs in this sample. That is not a profit calculation: the next tradable price, position size, spread, commission and slippage are absent.
- A distance threshold or persistence requirement may reduce activity, but it also changes the rule and can delay a trend signal. Repeat the step and trend samples after any such change.
| Bar | Close | HMA (16) | EMA (16) | Cross for both |
|---|
| 1 | 102 | 100.261 | 100.235 | Up |
| 2 | 98 | 100.158 | 99.972 | Down |
| 3 | 102 | 100.325 | 100.211 | Up |
| 4 | 98 | 100.136 | 99.951 | Down |
| 19 | 102 | 100.065 | 100.137 | Up |
| 20 | 98 | 99.935 | 99.885 | Down |
| 24 | 98 | 99.935 | 99.881 | Down |
Repeat the comparison on TradingView without changing the test
Add the built-in Hull Moving Average and Exponential Moving Average to the same standard candlestick chart. Set both lengths to 16, use the same close source and chart timeframe, and keep offsets at zero. Compare the main EMA plot, not an additional smoothing plot. Record the symbol, exchange feed, session, adjustment settings, dates and loaded history.
- Inspect both readings on the same completed candle. Values based on the current close can change while that candle is open. Chart-bar confirmation also does not confirm a separate higher-timeframe input.
- Select trend and range evaluation windows before seeing the winner. Keep a later period separate to check whether the behavior persists. Synthetic tests explain the filter; they cannot estimate market performance.
- For a strategy comparison, hold entry and exit definitions, sizing, costs and order-fill settings fixed. Record signal time separately from fill time. A bar-close signal with the usual next-tick market-order setup generally fills at the following open.
- Use the results to choose a tradeoff: HMA for testing a smaller trend-following delay with explicit overshoot handling; EMA for testing a recursive positive-weight average. Neither choice establishes profitability or removes range failures.
Turn the chosen rules into inspectable Pine Script
Give the Pine Script AI Coding Agent your own written rules: a shared source and length, an HMA/EMA selector, both plots, completed-bar signals and explicit order timing. Ask it to draft the script, then request a syntax check and review the generated calculations. Use TradingView to inspect timestamps and strategy behavior before relying on the result.
- Include the three sample definitions and expected values in your review notes. A syntax check can find supported compilation errors; it cannot prove that entries, exits or trading assumptions are correct.
- The next step is code for rules you can specify and inspect. It does not require access to proprietary scripts, account migration or automatic trade execution.