Tweak Your Technical Indicator
Maximize Your Trading Efficiency with Creative Adjustments to the Classic RSI Tool
While the RSI is traditionally used to identify overbought and oversold conditions, savvy traders know that tweaking its parameters can unlock a wealth of additional signals.
This article delves into an intermediate technique for customizing RSI, providing strategies to diversify your trading performance and gain a competitive edge in the market.
The RSI and Aim of the Experiment
The relative strength index (RSI) is a momentum oscillator that measures the speed and change of price movements. It was developed by J. Welles Wilder Jr. and introduced in his 1978 book.
The RSI oscillates between zero and 100 and is typically used to identify overbought or oversold conditions in a market. The RSI is calculated using the following formula:
where relative strength — RS is the average of n days’ up closes divided by the average of nnn days’ down closes. The typical default lookback period is 14.
Generally, traders use the following rule with the RSI:
Overbought: When the RSI is above 70, it suggests that a security may be getting overbought or overvalued and might be primed for a trend reversal or corrective pullback in price.
Oversold: When the RSI is below 30, it indicates that a security may be getting oversold or undervalued and could be ready for a price correction or reversal to the upside.
If you want to see more of my work, you can visit my website for the PDF books catalogue by simply following the link attached the picture:
Let’s Create a Simple Variation on the RSI
The RSI as we know it is just the tip of the iceberg. We can tweak it and make it as we want it. Let’s try something simple but creative. We will calculate a 5-period moving average on the RSI and use it as the main indicator. Let’s call it the colorful RSI for simplicity.
Here’s how it will look:
The above indicator is generated using the following code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar
//@version=5
indicator("Colorful RSI")
lookback = input(defval = 14, title = 'Lookback')
rsi = ta.sma(ta.rsi(close, lookback), 5)
hline(50)
hline(30)
hline(70)
rsiColor = rsi > rsi[1] ? color.green : color.red
plot(rsi, color = rsiColor)
I’ve called it colorful RSI because positive change is painted in green and negative change is painted in red.
But first, let’s explain the code a little bit so that you know what you’re doing. We start by defining the lookback period (window) of the RSI as an input that can be changed easily afterwards. We put the default value defval as 14 and call the whole element Lookback (which is accessible in the parameters of the indicator later).
Then, we define the rsi variable as being a moving average function of the rsi. Hence, the rsi variable equals the moving average function that takes the source as the RSI (instead of the close price) with a lookback of 5.
The statement hline is simply used to plot a horizontal line. And lastly, the coloring is a function of whether the RSI rises or drops. This is made through the variable rsiColor.
Let’s create trading rules based on the colorful RSI:
A bullish signal is generated whenever the indicator shapes a positive change after shaping a negative change all while being below 30.
A bearish signal is generated whenever the indicator shapes a negative change after shaping a positive change all while being above 70.
Use the following code to implement the signals on the colorful RSI:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar
//@version=5
indicator("Colorful RSI", overlay = true)
lookback = input(defval = 14, title = 'Lookback')
rsi = ta.sma(ta.rsi(close, lookback), 5)
rsiColor = rsi > rsi[1] ? color.green : color.red
bullish_signal = rsi > rsi[1] and rsi[1] < rsi[2] and rsi < 30
bearish_signal = rsi < rsi[1] and rsi[1] > rsi[2] and rsi > 70
plotshape(bullish_signal, style = shape.triangleup, color = color.green, location = location.belowbar, size = size.small)
plotshape(bearish_signal, style = shape.triangledown, color = color.red, location = location.abovebar, size = size.small)
The following chart shows a sample of the signals generated by the technique:
Note that this technique is just an example to show you how to think about indicators and how to create trading rules, in no way they were tested. It’s just a hypothetical example.
As you can see, bearish signals in a rising market are unlikely to provide any value. This is why a certain filter may be needed. How about we adjust the signals to the trend? Let’s take a moving average as an example to do this:
A bullish signal is generated whenever the indicator shapes a positive change after shaping a negative change all while being below 30.
A bearish signal is generated whenever the indicator shapes a negative change after shaping a positive change all while being above 70.
Use the following code to implement the trend adjustments:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar
//@version=5
indicator("Colorful RSI", overlay = true)
lookback = input(defval = 14, title = 'Lookback')
rsi = ta.sma(ta.rsi(close, lookback), 5)
rsiColor = rsi > rsi[1] ? color.green : color.red
bullish_signal = rsi > rsi[1] and rsi[1] < rsi[2] and rsi < 30 and close > ta.sma(close, 300)
bearish_signal = rsi < rsi[1] and rsi[1] > rsi[2] and rsi > 70 and close < ta.sma(close, 300)
plotshape(bullish_signal, style = shape.triangleup, color = color.green, location = location.belowbar, size = size.small)
plotshape(bearish_signal, style = shape.triangledown, color = color.red, location = location.abovebar, size = size.small)
The filter has wiped out more than 90% of the signals, leaving just two in the chart page.
Tweaking the RSI can significantly enhance its utility. It’s up to you to be creative.
You can also check out my other newsletter The Weekly Market Sentiment Report that sends weekly directional views every weekend to highlight the important trading opportunities using a mix between sentiment analysis (COT report, put-call ratio, etc.) and rules-based technical analysis.
If you liked this article, do not hesitate to like and comment, to further the discussion!