Donchian Channel Breakout Strategy

Author: ChaoZhang, Date: 2023-12-04 14:16:33



The Donchian Channel Breakout Strategy is a price action and trend following breakout trading strategy. It uses the upper and lower bands of the Donchian Channel to identify potential breakout points and takes long or short positions when prices break out of the channel.

Strategy Logic

The core logic of this strategy is:

  1. Use Ta.highest and Ta.lowest functions to calculate highest high and lowest low over a certain period (e.g. 60 bars) to construct the upper and lower bands of the Donchian Channel.

  2. When prices break above the upper band, it indicates an uptrend may be starting, so go long at next bar’s open after the upper band breakout. When prices break below the lower band, it indicates a downtrend may be starting, so go short at next bar’s open after lower band breakout.

  3. Once prices fall back below upper band or rise back above lower band, it indicates a trend reversal, so flatten existing long or short positions.

  4. To control risks, set stop loss at entry price minus/plus one minimum tick after initiating long/short positions.

This kind of channel breakout strategy is simple and straightforward, taking into account both price action and trend following, easy to execute and stable.


This strategy has several advantages:

  1. The logic is clear, simple and easy to understand, with high executability.

  2. Using Donchian Channel to determine trend direction can effectively filter out noise and identify reliable breakout signals.

  3. Reasonable stop loss setting after entry can well control single trade loss.

  4. No matter the market condition, the strategy can trade along with trend once valid breakout happens and catch potential big moves.

  5. Very few parameters, not prone to overfitting, with large tuning space and high plasticity.


There are also some risks with this strategy:

  1. As a trend following strategy, it cannot catch reversal moves.

  2. Stop loss too close may get stopped out by short-term price swings.

  3. Improper channel length setting increases false breakout probabilities.

Some counter measures:

  1. Incorporate other indicators to identify potential reversals, avoid blindly following trends.

  2. Use reasonable trailing stop to lock in profits instead of sticking to initial hard stop loss.

  3. Test different parameter values to find optimal combination.

Optimization Directions

There is room for further optimization:

  1. Try double Donchian channel breakout strategy, one for entry and one for stop loss/profit taking.

  2. Only taking trades after the breakout exceeds certain amount of ticks to filter some false breaks.

  3. Add volume or volatility filter to avoid bad trades when prices swing violently.

  4. Try different holding strategies like trend following or mean reversion in combination for better results.

  5. Add risk management modules to limit max daily loss, max drawdown etc.


In summary, the Donchian Channel Breakout Strategy is a very practical short-term trend following strategy. It identifies potential trend changes through price action, and utilizes channel breakouts to enter trades. The logic is simple and easy to execute, and can achieve decent results across various markets. With further optimizations like parameter tuning, stop loss mechanisms, reversal identification etc., significant performance lift can be expected. It serves as a great starting point strategy for algo trading.

start: 2023-11-03 00:00:00
end: 2023-12-03 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

// Step 1. Define strategy settings
strategy(title="Price action and breakout Channel Forexrn", overlay=true,
     pyramiding=0, initial_capital=100000,
     commission_value=4, slippage=2)

dochLen =, title="Price action and breackout Channel Forexrn")

// Position sizing inputs
usePosSize    = input.bool(true, title="Use Position Sizing?")
atrLen        =, title="ATR Length")
atrRiskOffset = input.float(4, title="ATR Risk Offset Multiple", step=0.25)

maxRisk = input.float(2, title="Max Position Risk %", step=.25, 
     minval=0.25, maxval=15)
maxExposure = input.float(10, title="Max Position Exposure %", step=1, 
     minval=1, maxval=100)
marginPerc =, title="Margin %", minval=1, maxval=100)

// Step 2. Calculate strategy values
upperband = ta.highest(high, dochLen)[1]
lowerband = ta.lowest(low, dochLen)[1]

// Calculate position size
riskEquity = (maxRisk * 0.01) * strategy.equity
riskTrade  = (ta.atr(atrLen) * atrRiskOffset) * syminfo.pointvalue

maxPos = ((maxExposure * 0.01) * strategy.equity) /
     ((marginPerc * 0.01) * (close * syminfo.pointvalue))

posSize = usePosSize ? math.min(math.floor(riskEquity / riskTrade), maxPos) : 1

// Step 3. Output strategy data
plot(upperband,, linewidth=2, title="DoCh Upperband")
plot(lowerband,, linewidth=2, title="DoCh Lowerband")

// Step 4. Determine trading conditions
tradeWindow  = true

tradeAllowed = tradeWindow and bar_index > dochLen

// Step 5. Submit entry orders
if tradeAllowed
    if strategy.position_size < 1
        strategy.entry("EL", strategy.long, qty=posSize,
             stop=upperband + syminfo.mintick)

    if strategy.position_size > -1
        strategy.entry("ES", strategy.short, qty=posSize,
             stop=lowerband - syminfo.mintick)

// Step 6. Submit exit orders
if not tradeWindow