Introduction
Welcome to this guide on the Donchian Channel, a powerful tool that has been shaping the world of trading for decades. Named after its creator, Richard Donchian, also known as “The Father of Trend Following”, this indicator has been a cornerstone in the strategies of many successful traders.
The Donchian Channel is a unique blend of simplicity and effectiveness, providing traders with valuable insights into market volatility and potential price breakouts. It’s a testament to the timeless relevance of Donchian’s work that this indicator continues to be widely used in today’s fast-paced, technology-driven trading environment.
In this guide, we will take a look at the intricacies of the Donchian Channel, exploring its origins, its mathematical construction, and its purpose by design. We will guide you on how to find buy and sell signals, discuss its pros and cons, and even show you how to code this into Python.
So, let’s learn to master Donchian Channels.
Origins of the Donchian Channel
The Donchian Channel, a trend-following indicator, is named after its inventor, Richard Donchian, a pioneer in the field of technical analysis and systematic trading. Born in 1905, Donchian’s contributions to the world of finance extend far beyond the creation of this renowned indicator. He is often referred to as “The Father of Trend Following” due to his significant influence on the development of trend-following strategies.
Richard Donchian began his career on Wall Street during the 1930s, a period marked by significant economic turmoil. Despite the challenging environment, Donchian’s innovative thinking led him to develop a series of trading strategies and indicators, the most famous of which is the Donchian Channel.
The Donchian Channel was created as a tool to identify potential breakouts in commodity markets. It was designed to track the highest high and the lowest low over a defined period, forming an “envelope” around the price action. This envelope or “channel” could then be used to identify potential breakouts, a key component of trend-following strategies.
Interestingly, the Donchian Channel gained widespread recognition when it was used by the Turtle Traders in the 1980s. The Turtle Traders were a group of novice traders who were taught to trade using a simple trend-following system, which included the use of the Donchian Channel. Their success further cemented the Donchian Channel’s place in trading history.
Despite the evolution of markets and trading technology, the Donchian Channel remains a relevant and widely used tool in today’s trading landscape. Its enduring popularity is a testament to Richard Donchian’s innovative thinking and his lasting impact on the world of trading.
Mathematical Construction of the Donchian Channel
The Donchian Channel is a relatively simple yet powerful indicator. It consists of an upper band, a lower band, and often includes the middle band, which is the average of the upper and lower bands. The mathematical construction of the Donchian Channel is straightforward and involves the following steps:
Upper Band: The upper band of the Donchian Channel is calculated by taking the highest price of a security over a set number of periods, typically 20. This is represented mathematically as:
Upper Band = Max(High (1-n))
Here, Max(High (1-n))
represents the highest high over the last ‘n’ periods.
Lower Band: The lower band is calculated by taking the lowest price of a security over the same number of periods. This is represented mathematically as:
Lower Band = Min(Low (1-n))
Here, Min(Low (1-n))
represents the lowest low over the last ‘n’ periods.
Middle Band: The middle band is the average of the upper and lower bands. This is represented mathematically as:
Middle Band = (Upper Band + Lower Band) / 2
Here, (Upper Band + Lower Band) / 2
calculates the average of the upper and lower bands.
In these formulas, ‘n’ represents the lookback period, which is the number of periods over which the highs and lows are considered. This is typically set to 20, but can be adjusted based on the trader’s preferences and the characteristics of the security being traded.
The upper and lower bands form a channel around the price action of the security, hence the name “Donchian Channel”. When the price hits the upper band, it could be an indication that the security is overbought, and when it hits the lower band, it could be an indication that the security is oversold. You would typically look to use this in mean reverting markets such as stock pairs or perhaps calendar spreads. The middle band can provide additional insights into the price trend of the security.
While the mathematical construction of the Donchian Channel is simple, its application in trading requires careful analysis and understanding of market conditions, it shouldn’t be relied on by itself.
Purpose and Design of the Donchian Channel
The Donchian Channel serves a dual purpose in technical analysis. It is designed to identify potential price breakouts, and it also provides insights into market volatility. By doing so, it helps traders formulate effective strategies to capitalize on market trends, making it a worthy piece of kit for many traders.
Identifying Price Breakouts
The primary purpose of the Donchian Channel is to identify potential price breakouts. A breakout occurs when the price of a security moves above the upper band or below the lower band of the Donchian Channel. This is often interpreted as a signal that the current trend is likely to continue.
If you look at a typical Donchian Channel chart there will be no past breakouts visible, which might seem confusing.
A “breakout” in the context of Donchian Channels refers to the current price moving above the highest high or below the lowest low of the past ‘n’ periods. When a breakout occurs, you will see the price move outside the channel on the chart. This is because the price has exceeded the highest high (for an upward breakout) or fallen below the lowest low (for a downward breakout) of the past ‘n’ periods.
However, in the next period, the Donchian Channel will adjust to include this new price, because the channel always shows the highest high and the lowest low of the past ‘n’ periods. So, after the breakout, the price will again appear to be within the channel on the chart, because the channel has adjusted to the new price level.
But not so fast. Some technical analysis software will appear to show past breakouts on their Donchian channel charts. For example here’s an intraday 1 min candle chart of Nasdaq with Donchian channel, approaching and after the Non-Farm Payrolls release today, the 8th July 2023, which came in weaker than the ADP report implied yesterday:
This is a fairly common method to plot the channel based on the high and low of the previous ‘n’ periods, not including the current period. This would mean that the channel for the current period is based on the high and low of the previous ‘n’ periods, and therefore the current price can breach the channel. This method can make it easier to visually identify breakouts when they occur, as seen above.
Assessing Market Volatility
As we already noted the Donchian Channel is also designed to provide insights into market volatility. The width of the channel, which is the difference between the upper and lower bands, visually reflects the volatility of the market. A wider channel indicates higher volatility, while a narrower, tighter channel suggests lower volatility. Look at the chart above, volatility is typically pretty dead before an important economic figure release so the channel is narrow and then explodes as the market absorbs the new information, vastly expanding it.
During periods of high volatility, the bands of the Donchian Channel expand as the highest high and the lowest low diverge. During periods of low volatility, the bands contract as the highest high and the lowest low converge. Understanding market volatility is crucial for risk management and can help traders decide when to enter or exit trades and assist with the placement of stops and profit targets.
Whether you’re looking for the best Donchian Channel strategy or simply exploring different technical indicators, understanding the purpose and design of the Donchian Channel and how different software might be coded can enhance your trading strategy and improve your trading results.
How to Find Buy and Sell Signals with the Donchian Channel
The Donchian Channel is a powerful tool for identifying potential buy and sell signals. Here’s how you can use it to enhance your trading strategy:
Buy Signals
A buy signal is generated when the price of a security breaks above the upper band of the Donchian Channel (see the section above for a deeper explanation). This is often interpreted as a sign that the security is entering a bullish phase, with prices expected to continue rising. Traders might consider entering a long position when this occurs.
Example: If the price of a stock moves above the upper band of its Donchian Channel, this could be a signal to buy the stock, anticipating further upward movement.
Sell Signals
Conversely, a sell signal is generated when the price of a security breaks below the lower band of the Donchian Channel (again the section above will help determine what you’re seeing). This is often seen as a sign that the security is entering a bearish phase, with prices expected to continue falling. Traders might consider entering a short position when this occurs.
Example: If the price of a stock moves below the lower band of its Donchian Channel, this could be a signal to sell the stock, anticipating further downward movement.
Pros and Cons of Using the Donchian Channel
Like any trading tool, the Donchian Channel has its strengths and weaknesses. Understanding these can help you make the most of this indicator.
Pros
- Easy to Interpret: The Donchian Channel is straightforward to calculate and easy to understand, making it accessible to traders of all experience levels.
- Adaptable: It can be used in various markets, including stocks, forex, commodities, and bonds. It’s also effective over different timeframes, from intraday to long-term trading.
- Identifying Breakouts: The Donchian Channel is excellent at identifying potential price breakouts, which can be valuable for trend-following strategies.
- Assessing Volatility: The width of the Donchian Channel can provide quick, visual insights into market volatility, aiding in risk management.
Cons
- Noise Sensitivity: The Donchian Channel can be sensitive to price noise, especially in volatile markets. This can lead to the generation of false signals, where the price appears to break the channel, but no sustained trend follows.
- Requires Confirmation: The Donchian Channel, by itself, does not provide enough information for reliable trading decisions. It often needs to be used in conjunction with other indicators or strategies to confirm signals and avoid false positives.
- Limited Information: While the Donchian Channel is excellent for identifying potential breakouts and volatility, it does not provide information about other important factors such as momentum or trend strength.
- Dependent on Parameter Selection: The effectiveness of the Donchian Channel can be heavily influenced by the selection of the lookback period. An inappropriate choice of parameters can lead to poor performance.
Coding and Plotting the Donchian Channel in Python
If you want to code your own version of the channel you can do so by following this step by step guide. We will be using Python (free) which I assume you have already installed and VSCode which is also free software available from Microsoft.
Step 1: Install necessary Python libraries
Before you start coding, you need to install the necessary Python libraries. Open VSCode, then open a new terminal (View -> Terminal). In the terminal, type the following commands to install the required libraries:
pip install pandas yfinance ta mplfinance matplotlib
Step 2: Import necessary Python libraries
In a new Python file, start by importing the necessary libraries. This is done using the import
statement.
import pandas as pd
import ta
import yfinance as yf
import mplfinance as mpf
import matplotlib.pyplot as plt
Step 3: Download the data
Next, we’ll download the price data for Gold from Yahoo Finance. We’ll use the yf.download
function, specifying the ticker symbol for Gold (‘GC=F’), and the start and end dates for the data we want to download.
# Download Gold price data from the start of the year to July 7th, 2023
data = yf.download('GC=F', start='2022-07-07', end='2023-07-07')
Step 4: Calculate the Donchian Channels
Now we’ll calculate the Donchian Channels. The upper band is the highest high over the last 20 days, the lower band is the lowest low over the last 20 days, and the middle band is the average of the upper and lower bands. We’ll use the rolling
and mean
functions from pandas to calculate these.
# Calculate the upper band (highest high over the last 20 days)
data['UB'] = data['High'].rolling(window=20).max()
# Calculate the lower band (lowest low over the last 20 days)
data['LB'] = data['Low'].rolling(window=20).min()
# Calculate the middle band (average of the upper and lower band)
data['MB'] = (data['UB'] + data['LB']) / 2
If you want to use a shorter time horizon, you can change the window
parameter to a smaller number. For example, if you want to use a 10-day Donchian Channel, you would change window=20
to window=10
.
Step 5: Clean up the data
The rolling
function we used to calculate the Donchian Channels creates NaN
values for the first 20 rows of the data, because there isn’t enough data to calculate the channels for these rows. We’ll use the dropna
function to remove these rows.
# Drop the first 20 rows which contain NaN values due to the rolling window calculation
data = data.dropna()
Step 6: Create a new DataFrame for the Donchian Channels
Next, we’ll create a new pandas DataFrame to hold the Donchian Channels. This will make it easier to plot the channels later.
# Create a new DataFrame for the Donchian Channels
dc = pd.DataFrame(index=data.index)
dc['UB'] = data['UB']
dc['MB'] = data['MB']
dc['LB'] = data['LB']
Step 7: Create the plot
Now we’re ready to create the plot. We’ll use the mplfinance
library to create a candlestick chart of the Gold price, and add the Donchian Channels as additional plots. We’ll also add a title and a label for the y-axis.
# Create a list of plots to be added
add_plots = [mpf.make_addplot(dc['UB'], color='g', linestyle='dashed'),
mpf.make_addplot(dc['MB'], color='b', linestyle='dashed'),
mpf.make_addplot(dc['LB'], color='r', linestyle='dashed')]
# Create a new figure and axes
fig, axes = mpf.plot(data, type='candle', style='yahoo', title='Gold Price with Donchian Channels',
ylabel='Price ($)', addplot=add_plots, figscale=1.25, figratio=(10, 7),
tight_layout=True, returnfig=True)
Step 8: Add a legend
To make the chart easier to read, we’ll add a legend that explains what each line represents.
# Create custom legend
legend_lines = [plt.Line2D([0], [0], color='g', lw=2, linestyle='dashed'),
plt.Line2D([0], [0], color='b', lw=2, linestyle='dashed'),
plt.Line2D([0], [0], color='r', lw=2, linestyle='dashed')]
axes[0].legend(legend_lines, ['UB', 'MB', 'LB'], loc='upper left')
Step 9: Show the plot
Finally, we’ll use the show
function from matplotlib to display the plot.
# Show the plot
plt.show()
Step 10: Run the code
Save your Python file, then run it by right-clicking in the file and choosing “Run Python File in Terminal”. You should see a chart of the Gold price with Donchian Channels.
If all has gone to plan you will end up with a chart looking like mine shown below:
Step 11: Adjusting the code to exclude the current period
If you want the channel to be plotted one period late (i.e., excluding the current period), the reasons for which are discussed earlier in this post in the Purpose and Design of the Donchian Channel section, you can adjust the code as follows:
# Calculate the upper band (highest high over the last 20 days, excluding the current day)
data['UB'] = data['High'].shift(1).rolling(window=20).max()
# Calculate the lower band (lowest low over the last 20 days, excluding the current day)
data['LB'] = data['Low'].shift(1).rolling(window=20).min()
# Calculate the middle band (average of the upper and lower band)
data['MB'] = (data['UB'] + data['LB']) / 2
The shift(1)
function shifts the data one period into the future, so the current period’s high and low are not included in the calculation of the Donchian Channels. This will make the channels appear one period late on the chart, and you will be able to see breakouts from the past.
With the modified code and zoomed in we get the above visible breakouts. This is the same way chart software such as Yahoo Finance create their channel plots if you want to compare yours with theirs. By having this understanding of what your code is doing you can go on to make better decisions when a making Donchian screener.
The Best Donchian Channel Strategy
The best Donchian Channel strategy is one that aligns with your trading style and risk tolerance. Here’s a simple yet effective strategy that many traders find useful:
- Setting the Channel: Set the Donchian Channel to a 20-day period. This is a common setting, but feel free to adjust it based on your trading style and the specific market you’re trading.
- Identifying Breakouts: Look for price breakouts above the upper band or below the lower band. These breakouts often indicate a potential trend.
- Confirming the Trend: Use another indicator, such as the Relative Strength Index (RSI) or Moving Average Convergence Divergence (MACD), to confirm the trend. This can help reduce the risk of false signals.
- Setting Stop-Loss and Take-Profit Levels: Set your stop-loss level below the lower band for long trades or above the upper band for short trades. Set your take-profit level at a point where you expect the price to reach based on the strength of the trend.
Remember, the best Donchian Channel strategy is one that fits your trading style and risk tolerance. Always test a new strategy in a demo account before using it in live trading.
Conclusion
Understanding the Donchian Channel can help you identify potential trading opportunities and manage risk more effectively.
From its origins to its mathematical construction, from identifying buy and sell signals to understanding its pros and cons, to a detailed python coding tutorial and comparing the output to that of commercial charting software, we hope this guide has given you valuable insights into the Donchian Channel and how to use it in your trading or automation.
Remember, the key to successful trading is not just about using the right tools, but also about understanding them thoroughly. So, keep learning, keep testing, and may your trading journey be a successful one! Let us know how you get on with it.
Frequently Asked Questions
- What is the Donchian Channel? The Donchian Channel is a trend-following indicator developed by Richard Donchian. It consists of an upper band, a lower band, and often a middle band, which is the average of the upper and lower bands.
- How is the Donchian Channel calculated? The upper band of the Donchian Channel is the highest high over a set number of periods, and the lower band is the lowest low over the same number of periods. The middle band is the average of the upper and lower bands.
- How do you use the Donchian Channel in trading? The Donchian Channel can be used to identify potential price breakouts and assess market volatility. A price breakout above the upper band may indicate a buying opportunity, while a breakout below the lower band may suggest a selling opportunity.
- What are the pros and cons of using the Donchian Channel? The Donchian Channel is simple to understand, versatile, and excellent at identifying potential price breakouts and assessing market volatility. However, it can be sensitive to price noise, requires confirmation from other indicators, provides limited information, and its effectiveness can depend on the choice of parameters.
Recommended music while trading this indicator – “Little Donkey”
You may wish to look at Bollinger Bands too.
Leave a Reply