strategy · on price · open source
Hull MA Crossover strategy
Hull MA Crossover is a free open-source strategy by @deepwick. Two Hull Moving Averages crossed against each other — both fast and almost lag-free. Deepwick Script runs a subset of Pine Script.
Running…
Loading chart…
What Hull MA Crossover does
Two Hull Moving Averages crossed against each other — both fast and almost lag-free. A non-trendline crossover that catches turns without the usual SMA drag.
- Default 9/21 looks like an SMA 14/28 but turns ~3 bars sooner.
- Raise both lengths for steadier swings; the sqrt(N) kernel keeps lag low.
- Excellent on crypto and indices where lag kills entries.
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("Hull MA Crossover", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
fastLen = input.int(9, "Fast HMA Length", minval=5, maxval=50, step=1)
slowLen = input.int(21, "Slow HMA Length", minval=20, maxval=200, step=1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorBg = input.color("color.purple", "Color Bg")
colorDim = input.color("color.maroon", "Color Dim")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
hmaFast = ta.wma(2 * ta.wma(close, math.floor(fastLen / 2)) - ta.wma(close, fastLen), math.round(math.sqrt(fastLen)))
hmaSlow = ta.wma(2 * ta.wma(close, math.floor(slowLen / 2)) - ta.wma(close, slowLen), math.round(math.sqrt(slowLen)))
longSignal = strategy.position_size == 0 and ta.crossover(hmaFast, hmaSlow)
exitSignal = strategy.position_size > 0 and ta.crossunder(hmaFast, hmaSlow)
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="HMA cross down")
p_Fast_HMA = plot(hmaFast, "Fast HMA", color=colorBg, linewidth=2)
p_Slow_HMA = plot(hmaSlow, "Slow HMA", color=colorDim, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "HMA long entry", "Fast HMA crossed above slow HMA")
alertcondition(exitSignal, "HMA exit", "Fast HMA crossed below slow HMA")
No comments yet.
Sign in to comment.