Relative Strength Index
Yaser Rahmati | یاسر رحمتی
Introduction
The Relative Strength Index (RSI) is a popular momentum oscillator used in technical analysis to measure the speed and change of price movements. It was developed by J. Welles Wilder and is used to identify overbought or oversold conditions in a market.
Understanding RSI
Calculation:
RSI is calculated using the following formula:
Where RS (Relative Strength) is the average of 'n' days' up closes divided by the average of 'n' days' down closes.
Interpretation
RSI values range from 0 to 100.
Overbought Condition: RSI above 70 suggests that the asset might be overbought and could be due for a pullback.
Oversold Condition: RSI below 30 suggests that the asset might be oversold and could be due for a rebound.
Example Data (14-day period)
Assume the following closing prices for 15 days:
Calculation Steps
Calculate the average gain and average loss for the first 14 days:
Total Gain
Total Loss
Average Gain
Average Loss
Calculate the Relative Strength (RS)
Calculate the RSI
Trading with RSI
1. Overbought/Oversold Levels
Buy Signal: When RSI crosses above the 30 level, indicating a potential rebound from oversold conditions.
Sell Signal: When RSI crosses below the 70 level, indicating a potential pullback from overbought conditions.
2. RSI Divergence
Bullish Divergence: Occurs when the price makes a new low but RSI makes a higher low. This can signal a potential upward reversal.
Bearish Divergence: Occurs when the price makes a new high but RSI makes a lower high. This can signal a potential downward reversal.
3. RSI Swing Rejections
Bullish Swing Rejection: RSI moves below 30, rebounds above 30, then pulls back but stays above 30, and finally moves higher. This pattern can signal a potential buying opportunity.
Bearish Swing Rejection: RSI moves above 70, pulls back below 70, rebounds but stays below 70, and finally moves lower. This pattern can signal a potential selling opportunity.
4. RSI Centerline Crossover
Bullish Signal: RSI crosses above the 50 level, indicating potential upward momentum.
Bearish Signal: RSI crosses below the 50 level, indicating potential downward momentum.
Pine Script Code for RSI
Here's a basic Pine Script code to plot RSI on TradingView:
//@version=5
: This line specifies that the script uses Pine Script version 5.indicator("Relative Strength Index (RSI)", overlay=false)
: This line declares an indicator named "Relative Strength Index (RSI)". Theoverlay=false
parameter means the RSI will be plotted in a separate pane below the price chart, not overlaid on the price chart.rsiPeriod = input.int(14, title="RSI Period", minval=1)
: This line creates an input field for the user to specify the period for the RSI calculation. The default value is set to 14, and the minimum allowable value is 1.rsiValue = ta.rsi(close, rsiPeriod)
: This line calculates the RSI value using the built-inta.rsi
function, which takes the closing prices and the specified period as arguments.plot(rsiValue, title="RSI", color=color.blue)
: This line plots the calculated RSI values on the chart with the title "RSI" and in blue color.hline(70, "Overbought", color=color.red)
: This line draws a horizontal line at the 70 level, marking the overbought threshold in red.hline(30, "Oversold", color=color.green)
: This line draws a horizontal line at the 30 level, marking the oversold threshold in green.bgcolor(rsiValue > 70 ? color.new(color.red, 90) : na, title="Overbought Background")
: This line changes the background color to a semi-transparent red (90% opacity) when the RSI value is above 70, indicating an overbought condition. If the RSI is not above 70, it does nothing (na
).bgcolor(rsiValue < 30 ? color.new(color.green, 90) : na, title="Oversold Background")
: This line changes the background color to a semi-transparent green (90% opacity) when the RSI value is below 30, indicating an oversold condition. If the RSI is not below 30, it does nothing (na
).
Keywords
Relative Strength Index
, RSI
, Momentum Oscillator
, Technical Analysis
, Overbought
, Oversold
, Trading Indicator
, RSI Divergence
, RSI Calculation
, RSI Strategy
, Price Momentum
, Trend Reversal
, Trading Signals
, Financial Markets
, RSI Period
, یاسر رحمتی
Last updated