0bps

Strategy vault / Breakout

Dual Channel Donchian Breakout Strategy

This strategy is based on the Donchian Channel indicator to implement trading signals on upper and lower band breakouts. The strategy calculates upper and lower bands with different parameters to generate buy and…

Author
ChaoZhang
Complexity
Starter · 44 lines
Parameters
3
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

This strategy is based on the Donchian Channel indicator to implement trading signals on upper and lower band breakouts.

Strategy Logic

The strategy calculates upper and lower bands with different parameters to generate buy and sell signals respectively.

Upper Band Formula: Upper = Highest(length1) Lower Band Formula: Lower = Lowest(length2) Mid Line Formula: Mid Line = (Upper + Lower) / 2

When close price breaks above upper band, a buy signal is generated. When close price breaks below lower band, a sell signal is generated.

The advantage of this strategy is the flexibility to customize upper and lower band parameters for more flexible trading rules.

Advantages

  1. Customizable upper and lower band parameters for independent long and short control.

  2. Mid line indicator shows average position of bands for clearer breakout judgment.

  3. Donchian Channel has trend following characteristic to catch trend opportunities.

  4. Simple logic and easy to implement.

Risks

  1. Vulnerable to false breakouts, needs filter from other indicators.

  2. Unable to detect trend divergence, requires manual or other indicator combination.

  3. Improper parameter tuning leads to over-aggressiveness or over-conservativeness.

Enhancement Directions

  1. Incorporate moving averages etc. to filter false breakouts.

  2. Add volatility measures to quantify true breakout probability.

  3. Dynamically adjust upper and lower band parameters for adaptive trading rules.

Conclusion

This strategy implements flexible breakout trading via dual-band Donchian Channel. Simple logic but contains certain false breakout probabilities. Can be improved by parameter tuning, filters and supplementary indicators.

Parameters

NameDefaultWhat it controls
v_input_120Upper Channel
v_input_220Lower Channel
v_input_3falseOffset Bars

Source Pine Script

/*backtest
start: 2022-12-19 00:00:00
end: 2023-12-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//Modified Donchian Channel with separate adjustments for upper and lower levels, with offset
// Strategy to buy on break upper Donchian and sell on lower Donchian
strategy("Donchian Backtest", overlay=true)

length1 = input(20, minval=1, title="Upper Channel")
length2 = input(20, minval=1, title="Lower Channel")
offset_bar = input(0,minval=0, title ="Offset Bars")
max_length = max(length1,length2)

upper = highest(length1)
lower = lowest(length2)

basis = avg(upper, lower)

l = plot(lower, style=line, linewidth=3, color=red, offset=1)
u = plot(upper, style=line, linewidth=3, color=green, offset=1)

plot(basis, color=yellow, style=line, linewidth=1, title="Mid-Line Average")
//break upper Donchian (with 1 candle offset) (buy signal)
break_up = (close >= upper[1])
//break lower Donchian (with 1 candle offset) (sell signal)
break_down = (close <= lower[1])


if break_up
    strategy.entry("buy", strategy.long,1)
if break_down
    strategy.close("buy")

//plot(strategy.equity)


    

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-26. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dual-Channel-Donchian-Breakout-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open