Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
When it comes to technical analysis, one of the most commonly used indicators is the Relative Strength Index (RSI), which measures the speed and change of price movements. Traders often use RSI to identify potential overbought or oversold conditions in a market. However, another powerful tool that many traders utilize alongside RSI is RSI Divergence, a technique that can provide insights into potential reversals or trend continuations.
In this article, we’ll explore how to create a RSI Divergence Indicator in Pine Script on TradingView and offer a free version for use.
RSI Divergence occurs when the price of an asset forms new highs or lows that are not reflected by the RSI. Divergence can indicate a weakening trend, potentially signaling a reversal or the end of a current trend.
TradingView’s Pine Script allows traders to automate and visualize custom indicators. Below is a simple and free Pine Script code that identifies RSI divergence and plots signals for potential trend reversals.
//@version=5
indicator("RSI Divergence", shorttitle="RSI Divergence", overlay=true)
// Input for RSI settings
rsiLength = input.int(14, title="RSI Length")
rsiSource = input.source(close, title="RSI Source")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
// Calculate the RSI
rsi = ta.rsi(rsiSource, rsiLength)
// Function to detect Bullish Divergence
bullishDiv = ta.lowest(rsi, rsiLength) > ta.lowest(rsiSource, rsiLength)
// Function to detect Bearish Divergence
bearishDiv = ta.highest(rsi, rsiLength) < ta.highest(rsiSource, rsiLength)
// Plotting Divergence Signals on the Chart
plotshape(bullishDiv, title="Bullish Divergence", location=location.belowbar, color=color.green, style=shape.labelup, text="Bullish Div")
plotshape(bearishDiv, title="Bearish Divergence", location=location.abovebar, color=color.red, style=shape.labeldown, text="Bearish Div")
// Plotting the RSI for reference
plot(rsi, color=color.blue, title="RSI Line")
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
ta.rsi function with a customizable length and source (typically the close price).ta.lowest and ta.highest functions to detect when price makes a new low or high, and compares it with the RSI’s corresponding low or high. If a divergence is detected, the script will generate an alert.Creating a RSI Divergence Indicator using Pine Script on TradingView can provide valuable insights into potential market reversals. The free version of the script shared above is easy to implement and can help you identify divergence in real time. While RSI divergence is a powerful tool, it’s always recommended to use it in combination with other technical analysis methods to improve your trading decisions.
Happy trading, and may your strategy lead to profitable trades!