strategy · on price · open source
Keltner Channel breakout strategy (20, 2×ATR)
Keltner Channel (20, 2×ATR) breakout: buy a close above the upper band, exit back at the middle line. Plain-English rules, code and a costed backtest. Deepwick Script runs a subset of Pine Script.
What the Keltner Channel Breakout strategy does
Keltner Channel breakout: enter when price closes above the upper band (EMA + ATR multiple), exit when it returns to the basis.
- Tighter
Multfor faster entries; raise it for stronger breakouts only. - Combine with a volume spike filter for higher-conviction entries.
- Plot the basis and upper band on the chart for visual confirmation.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
Length | 20 | 5 | 100 |
ATR Mult | 2 | 1 | 3 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("Keltner Channel Breakout", 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)
len = input.int(20, "Length", minval=5, maxval=100, step=1)
mult = input.float(2, "ATR Mult", minval=1, maxval=3, step=0.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)
colorNeutral = input.color("color.gray", "Color Neutral")
colorMid = input.color("color.orange", "Color Mid")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
[km, ku, kl] = ta.kc(close, len, mult)
longSignal = strategy.position_size == 0 and close > ku
exitSignal = strategy.position_size > 0 and close < km
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="Back to basis")
p_Basis = plot(km, "Basis", color=colorNeutral, linewidth=1)
p_Upper_KC = plot(ku, "Upper KC", color=colorMid, linewidth=1)
p_Lower_KC = plot(kl, "Lower KC", color=colorMid, linewidth=1)
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, "KC long entry", "Price broke above Keltner upper")
alertcondition(exitSignal, "KC exit", "Price returned to Keltner basis")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
Keltner or Bollinger breakout?
Keltner bands use the average range, Bollinger bands use standard deviation. Keltner bands are smoother, so breakouts are rarer. Compare both pages on the same symbol and costs.
What multiplier should I use?
2 is the default here; a lower multiplier gives earlier entries and more false breakouts, a higher one fewer and later ones.
No comments yet.
Sign in to comment.