HMA — Hull Moving Average
תוכן זה אינו זמין עדיין בשפה שלך.
Alan Hull’s low-lag average: extrapolate the difference between a half-period and full-period weighted average, then smooth the result over √n. Turns almost with price — and overshoots at sharp reversals, which is the trade, not a bug.
Signature
HMA(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Length. Default 9, bounds 2–400. |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
$$ \text{raw} = 2,\text{WMA}(C, n/2) - \text{WMA}(C, n), \quad \text{HMA} = \text{WMA}(\text{raw}, \lfloor\sqrt{n}\rfloor) $$
WMA weights the window linearly, newest heaviest.
Warmup
n + √n bars; the value tracks the raw close during the lead-in.
Reading the value
hma.valueprice > hma.valuehma.crossed_above(slow)Example
class HullTrend(Strategy): """Ride the Hull MA's direction.""" period = Param(21, min=2, max=400) trade = Symbol() sizing = FixedCapital()
def execute(self): hma = HMA(self.period, on=self.trade) if self.trade.close > hma.value and self.trade.is_flat: self.buy(self.trade, reason="Above HMA") if self.trade.close < hma.value and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Below HMA")Notes
- Alan Hull (2005). Integer truncation on
n/2and√nfollows the common convention. - Proven by an assert-via-trade run on SPY daily (matched an independent strategy-side WMA chain exactly on every bar; zero alarm trades).
- Lower lag than
DEMA/TEMAat the same period, at the cost of larger overshoot.