Dynamic Channel Breakout Strategy

Author: ChaoZhang, Date: 2023-11-13 10:33:44



This strategy utilizes the dynamic channel indicator to determine market direction based on channel breakouts, aiming to capture trend directionality. It mainly calculates the highest high and lowest low over a certain period to form upper and lower channels, generating trading signals when the price breaks through the channels.

Strategy Logic

The strategy uses the input function to set the channel period length to 20 days. It then calculates the highest high over the past 20 days as the upper band, and the lowest low over the past 20 days as the lower band.

The channel is filled with color. The area above the upper band is filled with green, and the area below the lower band is filled with red, forming a dynamic channel.

The 200-day moving average ema(close,200) is also plotted as a reference to determine the overall trend.

The strategy uses the ema as the benchmark to judge the major trend. When close is above the 200-day line, it indicates an uptrend. When close is below, it indicates a downtrend.

In an uptrend, if the closing price close breaks through the upper band, a long signal is generated. In a downtrend, if close breaks the lower band, a short signal is generated.

The long stop loss is set at the lower band or middle line based on the long/short rules. The short stop loss is set at the upper band or middle line.

Advantage Analysis

  1. The dynamic channel adapts to changing market trends.

  2. Trading signals are generated based on breakouts, following the trend trading principle.

  3. The major trend is determined by moving average, combined with channel breakouts.

  4. Flexible stop loss placement based on market conditions.

Risk Analysis

  1. Wrong judgement of the major trend may deviate from the market.

  2. Improper channel period setting increases incorrect trading.

  3. Stop loss being too close to the channel may increase being stopped out.

  4. Breakout signals have some lag, possibly missing the best entry point.


  1. Use multiple indicators to judge the major trend, reducing errors.

  2. Optimize channel period parameters for different market rhythms.

  3. Adjust stop loss position to have enough buffer.

  4. Add filters to screen entry signals.

Optimization Directions

  1. Add more indicators to judge the major trend, improving accuracy.

  2. Incorporate volume indicators to avoid false breakouts.

  3. Optimize channel period parameters for different products.

  4. Implement dynamic trailing stop loss.

  5. Add filters to improve signal quality and avoid unnecessary trades.


This strategy follows the trend trading principle overall, using dynamic channels to determine volatility range and generating signals from breakouts. It can effectively track trend changes and is a reliable trend following strategy. But major trend judgement and stop loss mechanisms need further optimization and filtering conditions should be added to improve robustness. The strategy suits mid-to-long term trend tracking, and can be combined with other strategies in a portfolio to hedge risks.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pratyush_trades

strategy("Donchian Indexes", overlay=true)

length = input(20)
longRule = input("Higher High", "Long Entry", options=["Higher High", "Basis"])
shortRule = input("Lower Low", "Short Entry", options=["Lower Low", "Basis"])
longSL=input("Lower Low", "LONG SL", options=["Lower Low", "Basis"])
shortSL=input("Higher High", "SHORT SL", options=["Higher High", "Basis"])

hh = highest(high, length)
ll = lowest(low, length)

up = plot(hh, 'Upper Band', color = color.green)
dw = plot(ll, 'Lower Band', color = color.red)
mid = (hh + ll) / 2
midPlot = plot(mid, 'Basis', color = color.orange)
fill(up, midPlot, color=color.green, transp = 95)
fill(dw, midPlot, color=color.red, transp = 95)
plot(ema(close,200), "ema", color=color.orange)

if (close>ema(close,200))
    if (not na(close[length]))
        strategy.entry("Long", strategy.long, stop=longRule=='Basis' ? mid : hh)

if (close<ema(close,200))
    if (not na(close[length]))
        strategy.entry("Short", strategy.short, stop=shortRule=='Basis' ? mid : ll)

if (strategy.position_size>0)
    strategy.exit(id="Longs Exit",stop=longSL=='Basis' ? mid : ll)

if (strategy.position_size<0)
    strategy.exit(id="Shorts Exit",stop=shortSL=='Basis' ? mid : hh)