Donchian Channel Breakout Strategy 427308
This strategy uses the Donchian Channel indicator to trade breakouts of the upper and lower bands, enabling trend following operations across stocks/futures/crypto/forex etc, belonging to medium-to-long-term trend…
Overview
This strategy uses the Donchian Channel indicator to trade breakouts of the upper and lower bands, enabling trend following operations across stocks/futures/crypto/forex etc, belonging to medium-to-long-term trend breakout strategies.
Strategy Logic
Calculate the highest high and lowest low over a given period (e.g. 20 days) to get the upper and lower bands.
The midline is the average of the upper and lower bands. Breaking upper band signals uptrend, breaking lower band signals downtrend.
When price closes above upper band, determine uptrend has started, go long to enter.
When price breaks below midline, take profit to exit.
Can reference backtest timeframe to generate actual trading signals.
Optionally, breaking lower band can also act as short signal.
The strategy determines trend start by channel breakouts, uses midline as profit taking exit, capturing mid-to-long term trends. Channel parameters can be adjusted to fit the market.
Advantage Analysis
Donchian Channel is simple to calculate and implement.
Price breaking channel signals trend change.
Midline as profit taking level is reasonably set.
Clear signal rules, easy to execute.
Can flexibly adjust channel parameters for different products and timeframes.
Can evaluate long term or short term trading performance.
Large expansion space, can introduce other technical indicators.
Risk Analysis
Channel breakout may lag, risking missed early opportunities.
Does not consider divergence before breakout, may generate false signals.
Fixed midline stop loss sensitive to market volatility.
Improper backtest period risks over-fitting.
Lacks stop loss, need to watch out for enlarged losses.
Optimization Directions
Test and optimize channel period parameters.
Evaluate other MA types as stop loss lines.
Add filters like volume indicators.
Add moving or trailing stop loss mechanisms.
Introduce machine learning to predict price breakouts.
Optimize money management, set profit ratio etc.
Consider combining long/short term operations or multiple products.
Summary
This strategy uses Donchian Channel to determine trend direction, trading breakouts, a typical mid-to-long term trend following approach. Optimizing channel parameters and adding other technical indicators can form a more robust breakout system. The clear and concise logic allows expansions, making it a foundational quant strategy module with great practical utility.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2000 | Backtest Start Year |
| v_input_2 | true | Backtest Start Month |
| v_input_3 | true | Backtest Start Day |
| v_input_4 | 2018 | Backtest Start Year |
| v_input_5 | 12 | Backtest Start Month |
| v_input_6 | true | Backtest Start Day |
Source Pine Script
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-15 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//future strategy
//strategy(title = "stub", default_qty_type = strategy.fixed, default_qty_value = 1, overlay = true, commission_type=strategy.commission.cash_per_contract,commission_value=2)
//stock strategy
strategy(title = "dc", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, overlay = true, commission_type=strategy.commission.cash_per_contract,commission_value=.005)
//forex strategy
//strategy(title = "stub", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, overlay = true)
//crypto strategy
//strategy(title = "stub", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, overlay = true, commission_type=strategy.commission.percent,commission_value=.25,default_qty_value=10000)
testStartYear = input(2000, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testEndYear = input(2018, "Backtest Start Year")
testEndMonth = input(12, "Backtest Start Month")
testEndDay = input(1, "Backtest Start Day")
testPeriodEnd = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testPeriod() =>
true
//time >= testPeriodStart ? true : false
dcPeriod = 20
dcUpper = highest(close, dcPeriod)[1]
dcLower = lowest(close, dcPeriod)[1]
dcAverage = (dcUpper + dcLower) / 2
plot(dcLower, style=line, linewidth=3, color=red, offset=1)
plot(dcUpper, style=line, linewidth=3, color=aqua, offset=1)
plot(dcAverage, color=yellow, style=line, linewidth=1, title="Mid-Line Average")
strategy.entry("simpleBuy", strategy.long, when=close >= dcUpper)
strategy.close("simpleBuy",when=close < dcAverage)
//strategy.entry("simpleSell", strategy.short,when=close <= dcLower)
//strategy.close("simpleSell",when=close > dcAverage)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-19. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Donchian-Channel-Breakout-Strategy-427308.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Breakout Strategy Based on Turtle TradingPine Script · Breakout · 1d
- Contrarian Donchian Channel Touch Entry Strategy with Post Stop Loss Pause and Trailing Stop LossPine Script · Breakout · 1d
- Donchian Breakout Trading StrategyPine Script · Breakout · 1d
- Donchian Channel Breakout Strategy 426772Pine Script · Breakout · 2h
- Donchian Channel Breakout Strategy 440321Pine Script · Breakout · 4h
- Donchian Channel Breakout Strategy 442842Pine Script · Breakout · 4h