Introduction
In the world of trading, technical analysis is a crucial tool that traders use to predict future price movements. Among the myriad of indicators available, the Williams Percent R, often abbreviated as Williams %R or simply %R, stands out for its effectiveness and versatility. This guide aims to provide an in-depth understanding of the %R indicator, a tool that has become a staple tool for many successful traders.
This particular indicator is a type of momentum indicator that was developed by renowned trader and author Larry Williams. It’s designed to identify overbought and oversold market conditions, providing traders with potential buy and sell signals. This guide will investigate the origins, mathematical construction, purpose by design, and how traders can interpret its signals to enhance their trading strategy. We will also give a step by step tutorial of how to code it into Python.
Let’s dive into the fascinating world of the Williams %R indicator and explore how it can help you navigate trading the markets.
Origins of the Williams Percent R Indicator
This is a momentum indicator that was developed by the esteemed trader and author Larry Williams. Larry Williams is a well-known figure in the trading world, with a career spanning over five decades. He has made significant contributions to the field of technical analysis and has developed several trading indicators, with the Williams %R being one of his most notable creations.
It was designed in the 1960s as a tool to help traders identify overbought and oversold conditions in the market. These conditions often precede reversals, providing traders with potential opportunities to enter or exit trades. It is particularly known for its ability to generate signals even in the most volatile of markets.
Mathematical Construction
The indicator is calculated using a relatively straightforward mathematical formula. It’s designed to measure the level of the close relative to the high-low range over a specific period, typically 14 periods. The formula is as follows:
Williams %R = (Highest High – Close) / (Highest High – Lowest Low) * -100
Let’s break down each component of this formula:
- Highest High: This is the highest price achieved in the look-back period, typically the last 14 periods.
- Close: This is the most recent closing price.
- Lowest Low: This is the lowest price recorded in the look-back period.
This is then multiplied by -100 to invert its scale, making the indicator oscillate between 0 (representing overbought conditions) and -100 (representing oversold conditions).
While the standard look-back period is 14 periods, traders can adjust this to suit their specific trading style and the characteristics of the asset they’re trading. For instance, a shorter look-back period will make it more sensitive to price changes, while a longer period will smooth out the indicator and result in fewer signals.
Purpose and Design
The primary purpose of the Williams %R is to help traders identify potential overbought and oversold conditions in the market. An asset is considered overbought when its price has risen significantly and may be poised for a pullback or reversal. Conversely, an asset is considered oversold when its price has fallen sharply and may be due for a bounce or reversal.
The Williams %R accomplishes this by comparing the closing price of an asset to its price range over a specified look-back period. By doing so, it provides a snapshot of where the price is currently situated relative to its recent high and low.
The design of the indicator is such that it oscillates between 0 and -100. As we’ll see in more detail below, a reading above -20 is typically considered overbought, suggesting that the asset may be overpriced and could be due for a price correction or reversal. Alternatively, a reading below -80 is typically considered oversold, indicating that the asset may be under-priced and could be due for a price bounce or reversal.
Just because an asset is in overbought or oversold territory according to the Williams %R, it doesn’t necessarily mean that a price reversal is imminent. Overbought and oversold conditions can persist for extended periods, especially in strong uptrends or downtrends. Therefore, it should be used in conjunction with other technical analysis tools and indicators to confirm potential trading signals and reduce the risk of false signals.
For example as I write this the Dow Jones Industrial Average daily cash chart in July 2023 has the indicator above -20 since 8 days ago (July 13th) but has risen another thousand points more in the mean time, which would be a painful short position.
How to Interpret Buy and Sell Signals
Overbought Conditions and Sell Signals
When the Williams %R rises above -20, it indicates that the asset may be overbought. In other words, the asset may be trading at a relatively high price and could be due for a price correction or reversal. However, it’s important to remember that overbought conditions can persist for extended periods in strong uptrends. Therefore, a reading above -20 is not a sell signal in itself. Traders should look for additional confirmation from other technical analysis tools or indicators before considering a sell trade. For instance, a bearish divergence between the indicator and the asset’s price could provide additional confirmation of a potential sell signal.
Oversold Conditions and Buy Signals
When the Williams %R falls below -80, it suggests that the asset may be oversold. This means that the asset may be trading at a relatively low price and could be due for a price bounce or reversal. However, just like overbought conditions, oversold conditions can persist for extended periods in strong downtrends. Therefore, a reading below -80 is not a buy signal in itself either. A bullish divergence between the indicator and the asset’s price may provide additional confirmation of a potential buy signal though.
According to Larry Williams’ original writing on this indicator, he suggests using a reading below -95 as a buy indication during bull markets and a reading above -10 as a sell signal during bear markets. This is slightly different from the commonly used thresholds of -20 and -80. However, he emphasizes that these signals should not be acted upon in isolation and should be used in conjunction with an understanding of the broader market context.
Divergences
Divergences between the Williams %R and the asset’s price can provide valuable trading signals. A bullish divergence occurs when the asset’s price forms lower lows, but the indicator forms higher lows. This could indicate that the downward momentum is waning and that a price reversal to the upside could be imminent. Conversely, a bearish divergence occurs when the asset’s price forms higher highs, but the indicator line forms lower highs. This could suggest that the upward momentum is weakening and that a price reversal to the downside could be on the horizon.
Pros and Cons
Pros
1. Identifies Overbought and Oversold Conditions: The Williams %R is excellent at identifying potential overbought and oversold conditions in the market which can help traders spot potential reversal points.
2. Generates Clear Signals: It generates clear and easy-to-interpret signals, making it a user-friendly tool for traders of all experience levels.
3. Versatile: It can be used in a variety of market conditions and on different timeframes, making it a versatile tool for different trading strategies.
Cons
1. False Signals: Like all technical indicators, this one can generate false signals too. Overbought and oversold conditions can persist for longer than expected, and price reversals may not occur immediately (see above where I give the current July 2023 DOW Jones readings).
2. Needs Confirmation: To reduce the risk of false signals, it should be used in conjunction with other technical analysis tools or indicators. This means that it may not be the best choice for traders looking for a standalone indicator.
3. Not Ideal for Trending Markets: While the Williams %R can be useful in range-bound markets, it may provide less reliable signals in strong trending markets. This is because overbought conditions can persist in a strong uptrend, and oversold conditions can persist in a strong downtrend.
Coding the Williams %R in Popular Trading Languages
Coding the indicator into popular trading languages like Python and R can be a valuable skill for traders who want to automate their trading strategies or conduct more sophisticated market analysis. Here’s a basic example of how you can calculate the Williams %R in Python using the pandas
library:
import pandas as pd
def calculate_williams_r(data, lookback):
high = data['High'].rolling(window=lookback).max()
low = data['Low'].rolling(window=lookback).min()
close = data['Close']
williams_r = ((high - close) / (high - low)) * -100
return williams_r
# Load your data into a pandas DataFrame
data = pd.read_csv('your_data.csv')
# Calculate the Williams %R with a lookback period of 14
data['Williams %R'] = calculate_williams_r(data, 14)
In this code, data
is a pandas DataFrame that contains the high, low, and close prices of an asset. The calculate_williams_r
function calculates the Williams %R for each row in the DataFrame based on a specified lookback period.
In R, you can use the TTR
package to calculate the Williams %R. Here’s a basic example:
# Install and load the TTR package
install.packages("TTR")
library(TTR)
# Load your data
data <- read.csv("your_data.csv")
# Calculate the Williams %R with a lookback period of 14
data$`Williams %R` <- WPR(Hi = data$High, Lo = data$Low, Cl = data$Close, n = 14)
In this code, data
is a data frame that contains the high, low, and close prices of an asset. The WPR
function from the TTR
package calculates the Williams %R for each row in the data frame based on a specified lookback period.
Plotting it on a Chart with Python
Here we provide a step-by-step guide on how to calculate the Williams %R for Dow Jones Industrial Average and plot it on a candlestick chart using Python in VSCode (free software from Microsoft):
- Install the necessary Python libraries. Open a new terminal in VSCode and run the following commands to install the necessary Python libraries:
pip install yfinance pandas mplfinance matplotlib
2. Create a new Python file. In VSCode, create a new Python file (e.g., williams_r.py
).
3. Import the necessary Python libraries. At the top of your Python file, import the necessary Python libraries:
import yfinance as yf
import pandas as pd
import mplfinance as mpf
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
4. Define a function to calculate the %R. Add the following function to your Python file to calculate it:
def calculate_williams_r(data, lookback):
high = data['High'].rolling(window=lookback).max()
low = data['Low'].rolling(window=lookback).min()
close = data['Close']
williams_r = ((high - close) / (high - low)) * -100
return williams_r
5. Download the data from Yahoo Finance. Use the yfinance
library to download the historical data for Dow Jones Industrial Average:
data = yf.download('^DJI', start='2022-07-01', end='2023-07-01')
6. Calculate the Williams %R. Use the calculate_williams_r
function to calculate the Williams %R for the downloaded data:
data['Williams %R'] = calculate_williams_r(data, 14)
7. Add overbought and oversold lines. Add two new columns to your DataFrame for the overbought and oversold levels:
data['Overbought'] = -20
data['Oversold'] = -80
8. Ensure the index is a DatetimeIndex. This is necessary for the mplfinance
library to correctly plot the data:
data.index = pd.DatetimeIndex(data.index)
9. Define the additional plots. Define the additional plots for the Williams %R and the overbought and oversold lines:
apd = [
mpf.make_addplot(data['Williams %R'], panel=2, color='b', secondary_y=False, ylabel='Williams %R'),
mpf.make_addplot(data['Overbought'], panel=2, color='red', secondary_y=False, linestyle='dashed'),
mpf.make_addplot(data['Oversold'], panel=2, color='green', secondary_y=False, linestyle='dashed')
]
10. Set the panel sizes. Set the panel sizes for the candlestick chart, the volume, and the Williams %R:
panel_sizes = (5, 1, 3)
11. Create the candlestick chart. Use the mplfinance
library to create a candlestick chart of the Dow Jones Industrial Average:
fig, axes = mpf.plot(data, type='candle', style='yahoo', addplot=apd, volume=True, panel_ratios=panel_sizes, title='Dow Jones Industrial Average and Williams %R', returnfig=True)
12. Create a legend. Create a legend for the Williams %R, overbought, and oversold lines:
legend_lines = [Line2D([0], [0], color=c, lw=1.5, linestyle=ls) for c, ls in zip(['b', 'red', 'green'], ['solid', 'dashed', 'dashed'])]
axes[2].legend(legend_lines, ['Williams %R', 'Overbought', 'Oversold'], loc='lower left')
13. Show the plot. Finally, show the plot with the following command:
mpf.show()
14. Run the Python file. Save the Python file and run it in VSCode, you can press the play icon in the top right to do that. This will download the historical data for Dow Jones Industrial Average futures, calculate the Williams %R, and plot it on a candlestick chart.
If everything has gone to plan you should end up with a chart that looks like mine shown here:
Now you are visualising what we have coded you can have the confidence to use the data outputs to create a Williams R screener and trigger alerts when your required parameters are picked up across a list of stocks, fx pairs, bonds or commodities.
Real-Life Trading Examples Using the Williams %R
Example 1: Bull Market
Let’s say you’re trading in a bull market, where prices are generally rising. You’re using the Williams %R with a lookback period of 14 days, and you’re using Larry Williams’ original threshold of -95 for bull market buy signals.
One day, you notice that the indicator has dropped below -95. This is a buy signal, indicating that the market may be oversold and a price increase could be imminent. You decide to buy.
Over the next few days, the market rises as expected, and the %R rises above -20. This is a sell signal, indicating that the market may be overbought and a price decrease could be imminent. You decide to sell, securing a profit from the trade.
Example 2: Bear Market
Now let’s say you’re trading in a bear market, where prices are generally falling. You’re using the same settings for the Williams %R as in the previous example.
One day, you notice that the Williams %R has risen above -10 (Williams’ threshold for a sell signal in a bear market). This is a sell signal, indicating that the market may be overbought and a price decrease could be imminent. You decide to sell short.
Over the next few days, the market falls as expected, and the indicator drops below -80. This is a buy signal, indicating that the market may be oversold and a price increase could be imminent. You decide to buy to cover your short position, securing a profit from the trade.
Example 3: Trading Ranges
Trading ranges present a unique challenge for many technical indicators, but the Williams %R can be particularly useful in these situations. In a trading range, prices oscillate between a high and a low point, creating a range. Look at the chart we created with Python above you can see a range between November 2022 and February 2023.
Suppose you’re using the Williams %R with a lookback period of 14 days, and you decide to use thresholds of -80 for buy signals and -20 for sell signals, the same as shown by dashed lines on the chart we created.
You can see you would have had three or four good range trades but you could translate this into much shorter timeframes perhaps intraday. Maybe you know the market is due to be range bound for several hours as you await important economic data releases later in the day, this would present a good opportunity for range trading reversals.
This process can be repeated each time the price reaches the bottom or the top of the trading range, potentially allowing you to profit from the price oscillations within the range.
Example 4: Combining with Momentum
Momentum is a concept in technical analysis that refers to the speed and strength of a price movement. Combining the Williams %R with a momentum indicator can provide additional confirmation for trading signals. The %R is often classified as a momentum oscillator because it measures the speed and change of price movements. However, it’s primarily used to identify overbought and oversold conditions, not necessarily to measure momentum in the same way as indicators like the Relative Strength Index (RSI) or the Moving Average Convergence Divergence (MACD).
In his original writing, Larry Williams suggests combining the Williams %R with other momentum indicators to confirm its signals and improve its reliability. This doesn’t mean that it isn’t a momentum indicator itself, but rather that it can benefit from the additional confirmation provided by other momentum indicators.
Let’s say you’re using the it in conjunction with a momentum indicator like the Relative Strength Index (RSI). You’re observing a bull market, and you’re using the Williams %R to identify potential buy signals.
One day, the it drops below -95%, indicating a potential buy signal. However, before you decide to buy, you check the RSI. The RSI is also in its oversold region, confirming the buy signal from the %R. With confirmation from both indicators, you decide to buy.
Over the next few days, the market rises, and both the Williams %R and the RSI rise into their overbought regions. This indicates a potential sell signal, and you decide to sell, securing a profit from the trade.
By combining the Williams %R with a momentum indicator, you can increase your confidence in the trading signals and potentially improve your trading performance.
As Williams himself said in his original notes:
“Not all signals will be correct. I have constructed no perfect indices. The Holy Grail is yet to be found.”
He goes on to say his ultimate protection is the use of stops and that he takes guidance from other indicators in addition to this.
Frequently Asked Questions about the Williams %R
1. What is the Williams %R?
The Williams %R, also known as Williams Percent Range, is a momentum indicator that measures overbought and oversold levels. It was developed by Larry Williams and is commonly used in technical analysis to provide potential buy and sell signals.
2. How is the Williams %R calculated?
The Williams %R is calculated using the following formula:
Williams %R = (Highest High – Close) / (Highest High – Lowest Low) * -100
Where:
- Highest High is the highest price over a specified lookback period.
- Close is the most recent closing price.
- Lowest Low is the lowest price over the lookback period.
3. How do I interpret the Williams %R?
The Williams %R oscillates between 0 and -100. A reading above -20 is typically considered overbought, suggesting that the asset may be due for a price correction or reversal. A reading below -80 is typically considered oversold, indicating that the asset may be due for a price bounce or reversal.
4. What are the limitations of the Williams %R?
The Williams %R is not infallible and can generate false signals. Overbought and oversold conditions can persist for longer than expected, and price reversals may not occur immediately. Therefore, the Williams %R should be used in conjunction with other technical analysis tools and indicators to confirm its signals.
5. How can I use the Williams %R in my trading strategy?
The Williams %R can be used in various ways in a trading strategy. It can be used to identify potential overbought and oversold conditions, providing potential buy and sell signals. It can also be used to identify divergences, which can signal potential price reversals. However, the Williams %R should always be used in conjunction with other technical analysis tools and indicators to confirm its signals.
6. What are the recommended settings for the Williams %R?
The standard lookback period for the Williams %R is 14 periods although Williams say it really depends on the market, ge said if forced to decide he would recommend 20 as a starting point. However, this can be adjusted to suit your specific trading style and the characteristics of the asset you’re trading. Larry Williams, its inventor, originally suggested using a reading below 95% as a buy signal for bull markets and a reading above 10% as a sell signal in bear markets. However, many traders use the thresholds of 20% and 80% to identify overbought and oversold conditions, respectively.
Key Takeaways:
- The indicator is a momentum oscillator developed by Larry Williams to identify overbought and oversold market conditions.
- It is calculated using the formula: Williams %R = (Highest High – Close) / (Highest High – Lowest Low) * -100.
- The indicator oscillates between 0 and -100, with readings above -20 indicating overbought conditions and readings below -80 indicating oversold conditions. Although as discussed Williams suggests other thresholds for bull and bear markets.
- It should be used in conjunction with other technical analysis tools and indicators to confirm potential trading signals and reduce the risk of false signals.
- Divergences between the Williams %R and the asset’s price can provide valuable trading signals.
- It has pros such as identifying overbought and oversold conditions, generating clear signals but it also has some cons such as the potential for false signals and the need for confirmation from other indicators.
- The indicator can be coded in popular trading languages like Python (as demonstrated) and R, allowing traders to automate their strategies and go on to create a Williams R stocks screener.
Leave a Reply