Donchian Channel Width Trading Strategy

Author: ChaoZhang, Date: 2024-02-04 10:35:11



The Donchian Channel Width trading strategy is a quantitative trading strategy developed based on the Donchian Channel indicator. This strategy calculates the difference between the highest price and the lowest price over a certain period, which is the width of the Donchian Channel, to judge the degree of market fluctuation and risk level. When the Donchian Channel width is greater than its smooth moving average, it indicates that market volatility has increased and is in a high-risk state. When it is smaller, it indicates that market volatility has decreased and is in a low-risk state. By making such judgments, the market trend and direction of operation can be clearly defined.

Strategy Principle

The core indicator of this strategy is the Donchian Channel width. The calculation formula of the Donchian Channel width is as follows:

Donchian Channel Width = Highest Price - Lowest Price

Where the highest price and the lowest price are calculated over a certain period n. This period is set through the length parameter.

In order to smooth the Donchian Channel width data, the strategy also introduces the smooth moving average (SMA) indicator. This indicator performs secondary calculation on the Donchian Channel width to reduce errors.

When judging the market risk level, if the Donchian Channel width is greater than its smooth moving average, it means that the market is entering a high volatility and high risk state. If it is smaller, it means that market volatility has weakened and is in a low risk state.

According to the judgment of the risk level, the strategy will make corresponding trading decisions: go short in high risk, and go long in low risk.

Advantage Analysis

The biggest advantage of this strategy is that it makes corresponding trading decisions by judging market risk through volatility. This can effectively prevent continuing to go long in a high-risk market, or still going short in a low-risk market, reducing unnecessary losses.

In addition, the strategy combines the Donchian Channel width and its smooth moving average to make the signal judgment more reliable and avoid erroneous transactions caused by data fluctuations.

In general, this strategy can judge market risk to a certain extent and make relatively stable trading decisions. This is its greatest advantage.

Risk Analysis

The main risk of this strategy is that the Donchian Channel width may not always accurately reflect market risk. When there is a divergence between the width and the average line, it may lead to wrong signals. Still trading mechanically at this time will lead to greater losses.

In addition, the setting of trading parameters will also have a significant impact on strategy returns. If the parameters are set improperly, it will also increase the possibility of loss.

Finally, under the condition of violent market fluctuations, the effect of the Donchian Channel width indicator will also be discounted, and the strategy signal will lag. Manual intervention is required at this time to suspend the strategy and avoid unnecessary losses.

Optimization Directions

This strategy can be optimized in the following aspects:

  1. Optimize the Donchian Channel width indicator. Different cycle parameters can be tested to find the best parameter combination.

  2. Increase other secondary indicators for confirmation. For example, the use of indicators such as volatility and volume can improve the accuracy of signals.

  3. Increase stop loss strategy. Reasonable stop loss can greatly reduce the size of single loss and significantly improve overall returns.

  4. Parameter self-adaptive optimization. Enable trading parameters to adjust dynamically according to real-time market changes to better adapt to the market.

  5. Algorithm trading optimization. Introduce algorithmic trading techniques such as machine learning to make strategies more intelligent and forward-looking.


The Donchian Channel width trading strategy makes corresponding trading decisions by judging the volatility and risk level of the market. The biggest advantage of this strategy is that it effectively controls risks and avoids chasing orders in high-risk markets. The strategy can be optimized in multiple dimensions to eventually achieve stable profits.

start: 2024-01-04 00:00:00
end: 2024-02-03 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

//  Copyright by HPotter v1.0 12/02/2018
// The Donchian Channel was developed by Richard Donchian and it could be compared 
// to the Bollinger Bands. When it comes to volatility analysis, the Donchian Channel 
// Width was created in the same way as the Bollinger Bandwidth technical indicator was.
// As was mentioned above the Donchian Channel Width is used in technical analysis to measure 
// volatility. Volatility is one of the most important parameters in technical analysis. 
// A price trend is not just about a price change. It is also about volume traded during this 
// price change and volatility of a this price change. When a technical analyst focuses his/her 
// attention solely on price analysis by ignoring volume and volatility, he/she only sees a part 
// of a complete picture only. This could lead to a situation when a trader may miss something and 
// lose money. Lets take a look at a simple example how volatility may help a trader:
//    Most of the price based technical indicators are lagging indicators.
//    When price moves on low volatility, it takes time for a price trend to change its direction and 
// it could be ok to have some lag in an indicator.
//    When price moves on high volatility, a price trend changes its direction faster and stronger. 
// An indicator's lag acceptable under low volatility could be financially suicidal now - Buy/Sell signals could be generated when it is already too late.
// Another use of volatility - very popular one - it is to adapt a stop loss strategy to it:
//    Smaller stop-loss recommended in low volatility periods. If it is not done, a stop-loss could 
// be generated when it is too late.
//    Bigger stop-loss recommended in high volatility periods. If it is not done, a stop-loss could 
// be triggered too often and you may miss good trades.
//You can change long to short in the Input Settings
//- For purpose educate only
//- This script to change bars colors.
strategy(title="Donchian Channel Width Strategy")
length = input(50, minval=1)
smoothe = input(50, minval=1)
reverse = input(false, title="Trade reverse")
xUpper = highest(high, length)
xLower = lowest(low, length)
xDonchianWidth = xUpper - xLower
xSmoothed = sma(xDonchianWidth, smoothe)
pos = iff(xDonchianWidth > xSmoothed, -1,
       iff(xDonchianWidth < xSmoothed, 1, nz(pos[1], 0))) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1, 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	   	    
barcolor(possig == -1 ? red: possig == 1 ? green : blue )  
plot(xDonchianWidth, color=blue, title="DCW")
plot(xSmoothed, color=red, title="sDCW")