RSI (Relative Strength Index) Strategy

A momentum oscillator that measures the speed and change of price movements. Buy when RSI enters oversold territory and sell when it enters overbought territory.

Type
Momentum
Timeframe
Any
Complexity
Beginner
Best For
Range-bound Markets

How It Works

Buy Signal (Oversold)

When RSI falls below the oversold level (typically 30) and then crosses back above it, it indicates the asset may be undervalued. Enter a long position.

Sell Signal (Overbought)

When RSI rises above the overbought level (typically 70) and then crosses back below it, it indicates the asset may be overvalued. Enter a short position or close long.

Strategy Parameters

ParameterDefaultDescription
RSI Length14Number of periods for RSI calculation
Oversold Level30RSI level indicating oversold condition
Overbought Level70RSI level indicating overbought condition

Implementation

//@version=5
strategy("RSI Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Input parameters
rsiLength = input.int(14, title="RSI Length", minval=1)
overSold = input.int(30, title="Oversold Level", minval=1, maxval=100)
overBought = input.int(70, title="Overbought Level", minval=1, maxval=100)
src = input.source(close, title="Source")

// Calculate RSI
rsi = ta.rsi(src, rsiLength)

// Plot RSI
plot(rsi, color=color.purple, title="RSI")
hline(overBought, color=color.red, linestyle=hline.style_dashed, title="Overbought")
hline(overSold, color=color.green, linestyle=hline.style_dashed, title="Oversold")
hline(50, color=color.gray, linestyle=hline.style_dotted)

// Generate signals
longCondition = ta.crossover(rsi, overSold)
shortCondition = ta.crossunder(rsi, overBought)

// Entry conditions
if (longCondition)
    strategy.entry(id="Long", direction=strategy.long)

if (shortCondition)
    strategy.entry(id="Short", direction=strategy.short)

// Exit conditions - close opposite positions
if (longCondition)
    strategy.close(id="Short")

if (shortCondition)
    strategy.close(id="Long")

// Plot signals on chart
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.tiny, text="RSI BUY")
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.tiny, text="RSI SELL")

// Alert conditions
alertcondition(longCondition, title="Buy Alert", message="RSI Oversold - Enter Long")
alertcondition(shortCondition, title="Sell Alert", message="RSI Overbought - Enter Short")

Advantages

  • Simple and easy to understand
  • Clear overbought/oversold signals
  • Works well in ranging markets
  • Popular and widely used

Disadvantages

  • Can remain overbought/oversold for extended periods in strong trends
  • False signals in trending markets
  • No clear exit strategy
  • Can produce whipsaws in volatile markets

© 2026 Pravidhi. All rights reserved.