
The Donchian Channel Breakout Strategy is a trend-following quantitative trading strategy. It utilizes Donchian Channels to capture market trends while using an ATRSL trailing stop to manage risk. When the price breaks above the upper band of the Donchian Channel, the strategy enters a long position; when the price falls below the ATRSL trailing stop line, the strategy closes the position.
donLength parameter, calculate the highest high and lowest low of the past donLength periods as the upper band donUpper and lower band donLower of the Donchian Channel, respectively. The midline donBasis is the average of the upper and lower bands.AP2 and AF2 parameters, calculate the ATR value SL2. Then, dynamically adjust the trailing stop price Trail2 according to the relationship between the current close price SC and the previous trailing stop price Trail2[1].donLength, AP2, and AF2 according to their needs to optimize strategy performance.The Donchian Channel Breakout Strategy is a classic trend-following strategy that captures trends using Donchian Channels and manages risk with an ATRSL trailing stop. The strategy’s advantages include its simple and clear logic, ease of implementation, and potential for optimization. However, its drawbacks include poor performance during choppy markets and trend reversals, and significant impact of parameter settings on strategy performance. In practical application, the strategy can be enhanced by adding trend filters, optimizing stop loss, and incorporating position sizing modules to improve stability and profitability. At the same time, it is important to control trading frequency and costs, and flexibly adjust strategy parameters based on market characteristics and personal risk preferences.
/*backtest
start: 2023-03-16 00:00:00
end: 2024-03-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Stock Trend USE THIS", overlay = true)
donLength = input(100, minval=1)
//Donchian Long
donLower = lowest(donLength)
donUpper = highest(donLength)
donBasis = avg(donUpper,donLower)
// ATRSL
SC = close
// Slow Trail //
AP2 = input(10, title="Slow ATR period") // ATR Period
AF2 = input(3, title="Slow ATR multiplier") // ATR Factor
SL2 = AF2 * atr(AP2) // Stop Loss
Trail2 = 0.0
iff_3 = SC > nz(Trail2[1], 0) ? SC - SL2 : SC + SL2
iff_4 = SC < nz(Trail2[1], 0) and SC[1] < nz(Trail2[1], 0) ? min(nz(Trail2[1], 0), SC + SL2) : iff_3
Trail2 := SC > nz(Trail2[1], 0) and SC[1] > nz(Trail2[1], 0) ? max(nz(Trail2[1], 0), SC - SL2) : iff_4
// Long and Short Conditions
longCondition = (crossover(close,donUpper[1]))
// Close Conditions
closeLongCondition = crossunder(close,Trail2)
// Strategy logic
if (longCondition)
strategy.entry("Long", strategy.long)
alert("Open Long position")
if (closeLongCondition)
strategy.close("Long")
alert("Close Long position")
// Plot Donchian
l = plot(donLower, color=color.blue)
u = plot(donUpper, color=color.blue)
plot(donBasis, color=color.orange)
fill(u, l, color=color.blue)
plot(Trail2, color=color.blue, title="ATRSL Trail")