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:

RSI=1001001+RSRSI=100-\frac{100}{1+RS}

Where RS (Relative Strength) is the average of 'n' days' up closes divided by the average of 'n' days' down closes.

RS=Average  GainAverage  LossRS=\frac{Average \; Gain}{Average \; Loss}

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

1+1+2+2+2+1+2+1=121+1+2+2+2+1+2+1=12
  • Total Loss

2+1+2+1+1=72+1+2+1+1=7
  • Average Gain

12140.857\frac{12}{14}\approx 0.857
  • Average Loss

714=0.5\frac{7}{14}=0.5
  • Calculate the Relative Strength (RS)

RS=Average  GainAverage  Loss=0.8570.51.714RS=\frac{Average \; Gain}{Average \; Loss}=\frac{0.857}{0.5}\simeq 1.714
  • Calculate the RSI

RSI=1001001+RS=1001001+1.71463.17RSI=100-\frac{100}{1+RS}=100-\frac{100}{1+1.714}\simeq 63.17

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
indicator("Relative Strength Index (RSI)", overlay=false)

// Input for the RSI period
rsiPeriod = input.int(14, title="RSI Period", minval=1)

// Calculate the RSI
rsiValue = ta.rsi(close, rsiPeriod)

// Plot the RSI
plot(rsiValue, title="RSI", color=color.blue)

// Overbought and oversold levels
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)

// Highlight overbought and oversold regions
bgcolor(rsiValue > 70 ? color.new(color.red, 90) : na, title="Overbought Background")
bgcolor(rsiValue < 30 ? color.new(color.green, 90) : na, title="Oversold Background")
  • //@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)". The overlay=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-in ta.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