This strategy is a long term trend following strategy based on Donchian Channels. It uses the upper and lower bands of Donchian Channels to find price breakouts and enter the market when a breakout occurs. It also uses the middle band as a trailing stop to exit positions. This strategy is suitable for markets with clear trends and can capture long term trends for high profits.
The strategy uses Donchian Channels with a length of 20 periods. The upper band is the highest high of the last 20 periods and the lower band is the lowest low of the last 20 periods. The default length of the middle band is 2 times that of the upper and lower bands, but can also be set to the same length. When price breaks above the upper band, go long. When price breaks below the lower band, go short. Exit long positions when price falls below the middle band. Exit short positions when price rises above the middle band.
Using a longer middle band allows profitable positions more room to run when a trend exists in the market, resulting in higher possible profits. In fact, the middle band with length of 2 times of upper/lower bands is very close to the 3 x ATR trailing stop recommended by Wilder. So this longer middle band can serve as an alternative trailing stop method for trend following strategies.
The advantages of this strategy are:
There are also some risks with this strategy:
The risks can be reduced by fine tuning the middle band length or incorporating other stop loss methods. Additional filters on entry logic can also help avoid unnecessary trades.
Some ways to optimize this strategy:
In summary, this is a very simple long term trend following strategy using Donchian Channels for trend direction and entries, with a middle band trailing stop. It can achieve high profits when used in strongly trending markets. But there are also risks that need to be addressed through parameter tuning and stop loss optimization to make the strategy more robust.
/*backtest start: 2024-01-07 00:00:00 end: 2024-01-14 00:00:00 period: 15m basePeriod: 5m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // Donchian Channels Strategy - Long Term Trend // by SparkyFlary //For Educational Purposes //Results can differ on different markets and can fail at any time. Profit is not guaranteed. strategy("Donchian Channels Strategy - Long Term Trend", shorttitle="Donchian Channels LT Strategy", overlay=true) length = input(20, title="Donchian Channel length") option = input("double", title="Middleband length: regular or double", options=["regular","double"]) upperband = highest(high, length)[1] lowerband = lowest(low, length)[1] middlebandLength = option=="double"?length*2:length middleband = avg(highest(high, middlebandLength)[1], lowest(low, middlebandLength)[1]) //Plots ubP = plot(upperband, title="Upperband", style=plot.style_line, linewidth=2) lbP = plot(lowerband, title="Lowerband", style=plot.style_line, linewidth=2) mbP = plot(middleband, title="Middleband", style=plot.style_line, color=color.maroon, linewidth=2) //Strategy buy = close > upperband sell = close < middleband short = close < lowerband cover = close > middleband strategy.entry(id="enter long", long=true, when=buy) strategy.close(id="enter long", comment="exit long", when=sell) strategy.entry(id="enter short", long=false, when=short) strategy.close(id="enter short", comment="exit short", when=cover)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6