Indicator · Pine Script v5 · On the chart

RSI Oversold Recovery

by vamseeachanta

Tracks RSI recovery from oversold territory on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code63
Settings5inputs
LicenceMIT
Last update5 weeks ago22 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

63 lines of Pine Script v5 from docs/domain/stocks/tradingview/rsi_oversold_recovery.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

rsi_oversold_recovery.pine
//@version=5
indicator("RSI Oversold Recovery", overlay=true)

// Input Parameters
rsiLen = input.int(14, "RSI Length", minval=1)
maLen = input.int(9, "MA Length", minval=1)
oversold = input.float(30, "Oversold Level", 0, 100)
overbought = input.float(70, "Overbought Level", 0, 100)
showLabels = input.bool(true, "Show Labels")

// Calculations
price = (high + low + close + open) / 4
rsi = ta.rsi(price, rsiLen)
rsiMA = ta.sma(rsi, maLen)

// State Management
var bool inOversoldTracking = false
var bool firstCrossDetected = false
var int daysInOversold = 0

// Condition Detection
isOversold = rsi < oversold
rsiCrossesMA = ta.crossover(rsi, rsiMA)

// State Logic
if isOversold and not inOversoldTracking
    inOversoldTracking := true
    firstCrossDetected := false
    daysInOversold := 1
else if inOversoldTracking
    if isOversold
        daysInOversold += 1
    
    if rsi >= oversold and not firstCrossDetected
        inOversoldTracking := false
        daysInOversold := 0
    else if rsiCrossesMA and not firstCrossDetected
        firstCrossDetected := true
    else if isOversold and firstCrossDetected and rsiCrossesMA
        // Buy Signal Condition
        label.new(bar_index, low, "BUY\n" + str.tostring(rsi, "#.##"), 
             color=color.green, style=label.style_label_up, textcolor=color.white)
        inOversoldTracking := false
        daysInOversold := 0

// Visual Elements
if showLabels
    if inOversoldTracking and not firstCrossDetected
        label.new(bar_index, high, "WATCH\nRSI: " + str.tostring(rsi, "#.##"), 
             color=color.yellow, style=label.style_label_down)
    if firstCrossDetected and inOversoldTracking
        label.new(bar_index, high, "ALERT\nRSI: " + str.tostring(rsi, "#.##"), 
             color=color.orange, style=label.style_label_down)

// Plots
plotRSI = plot(ta.sma(close, 1), "Price", color=color.new(color.blue, 70))
plotMA = plot(ta.sma(close, 20), "MA", color=color.new(color.red, 70))
fill(plotRSI, plotMA, color=color.new(color.gray, 90))

// Alerts
alertcondition(inOversoldTracking and not firstCrossDetected, "Watch Mode", "Stock entered oversold territory")
alertcondition(firstCrossDetected and inOversoldTracking, "Alert Mode", "First RSI-MA cross detected")
alertcondition(isOversold and firstCrossDetected and rsiCrossesMA, "Buy Signal", "Buy condition met")

Overview

RSI is calculated on the average of open, high, low and close, with a moving average of the RSI. When RSI drops below the oversold level the script shows a watch label, marks an alert after RSI crosses its moving average, and prints a buy label when a second cross happens while still oversold. Alert conditions are provided for each stage. It also plots simple price averages.

Details

Published by

vamseeachanta on GitHub

Draws

On the price chart

Markets

Stocks

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Lengthint14rsiLen
MA Lengthint9maLen
Oversold Levelfloat30oversold
Overbought Levelfloat70overbought
Show LabelsbooltrueshowLabels
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study
147 stars

This indicator combines Bollinger Bands, RSI, Stochastic RSI, and volume spike detection to identify mean-reversion conditions during range-bound market regimes. It calculates Bollinger Band width to identify low-volatility states and triggers buy or sell sign

Indicator v5 Oscillators & momentumVolatility & bands
Updated 6 weeks ago · MIT GitHub repository of BTC Dec 2025 — Range + Gamma Flush
53 stars

This overlay indicator calculates the 14-period Relative Strength Index to identify overbought and oversold market conditions. When RSI crosses key thresholds, it plots initial long or short entry labels directly on the price chart. If price continues moving a

Indicator v6 Oscillators & momentumMean reversion
Updated 2 months ago · MPL-2.0 GitHub repository of RSI Multi-Layer Entry Indicator

RSI Technique - V

by Tikam02
20 stars

RSI Technique - V identifies rapid reversal pivot points based on the Relative Strength Index. It monitors an RSI oscillator, configurable via the lookback setting, looking for sharp V-shaped spikes around extreme zones. A bullish signal appears when the indic

Indicator v5 Oscillators & momentumMean reversion
Updated 2 years ago · Apache-2.0 GitHub repository of RSI Technique - V

Commodity Heat Reversal plots score-based mean-reversion reversal markers on the price chart for commodity futures, aimed at the four-hour timeframe. It builds separate long and short heat scores from ATR distance to a mean moving average, ATR expansion, RSI e

Indicator v6 Mean reversionVolatility & bands
Updated 2 days ago · MIT GitHub repository of Commodity Heat Reversal [WavesUnchained]

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers