Indicator · Pine Script v6 · On the chart

Reversal RSI Stochastic ATR

by rubbermetal· code credited to claygrace74

Reversal RSI Stochastic ATR is an indicator that prints a reversal label when RSI is beyond its oversold or overbought level and the stochastic K line crosses D inside its own extreme zone.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code106
Settings13inputs
LicenceMPL-2.0
Last update4 months ago10 Jun 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

106 lines of Pine Script v6 from Reversal Strategy.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Reversal Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © claygrace74

//@version=6
indicator("Reversal RSI Stochastic ATR", shorttitle="Reversal", overlay=true)

// ==================== RSI Settings ====================
var rsi_group = "RSI Settings"
rsi_length     = input.int(14, "RSI Length", minval=1, group=rsi_group)
rsi_overbought = input.int(70, "RSI Overbought", minval=50, maxval=100, group=rsi_group)
rsi_oversold   = input.int(30, "RSI Oversold", minval=0, maxval=50, group=rsi_group)

// ==================== Stochastic Settings ====================
var stoch_group = "Stochastic Settings"
stoch_length     = input.int(14, "Stochastic Length", minval=1, group=stoch_group)
stoch_k          = input.int(3, "%K Smoothing", minval=1, group=stoch_group)
stoch_d          = input.int(3, "%D Smoothing", minval=1, group=stoch_group)
stoch_overbought = input.int(80, "Stoch Overbought", minval=50, maxval=100, group=stoch_group)
stoch_oversold   = input.int(20, "Stoch Oversold", minval=0, maxval=50, group=stoch_group)

// ==================== ATR Settings ====================
var atr_group = "ATR Risk Management"
atr_length     = input.int(14, "ATR Length", minval=1, group=atr_group)
atr_multiplier = input.float(1.5, "ATR Multiplier", minval=0.5, step=0.5, group=atr_group)

// ==================== Display Settings ====================
var disp_group = "Display Settings"
i_showSignals = input.bool(true, "Show Entry Signals", group=disp_group)
i_showSLTP    = input.bool(true, "Show SL/TP Lines", group=disp_group)
i_showInfo    = input.bool(true, "Show Info Table", group=disp_group)

// ==================================================================================
// Core Calculations
// ==================================================================================
rsi = ta.rsi(close, rsi_length)
stoch_k_line = ta.sma(ta.stoch(close, high, low, stoch_length), stoch_k)
stoch_d_line = ta.sma(stoch_k_line, stoch_d)
atr = ta.atr(atr_length)

// Reversal signals — RSI extreme + stochastic K/D cross in extreme zone
long_signal  = rsi < rsi_oversold and stoch_k_line < stoch_oversold and ta.crossover(stoch_k_line, stoch_d_line)
short_signal = rsi > rsi_overbought and stoch_k_line > stoch_overbought and ta.crossunder(stoch_k_line, stoch_d_line)

// ATR-based SL/TP
var float entrySL = na
var float entryTP = na
var float entryPrice = na
var bool  isLong = false

if long_signal
    entryPrice := close
    entrySL := close - atr * atr_multiplier
    entryTP := close + atr * atr_multiplier
    isLong := true
if short_signal
    entryPrice := close
    entrySL := close + atr * atr_multiplier
    entryTP := close - atr * atr_multiplier
    isLong := false

// Check if SL/TP hit (to clear lines)
slHit = (isLong and not na(entrySL) and low <= entrySL) or (not isLong and not na(entrySL) and high >= entrySL)
tpHit = (isLong and not na(entryTP) and high >= entryTP) or (not isLong and not na(entryTP) and low <= entryTP)

if slHit or tpHit
    entrySL := na
    entryTP := na
    entryPrice := na

// ==================================================================================
// Plots
// ==================================================================================

// Entry signals
plotshape(i_showSignals and long_signal,  style=shape.triangleup,   location=location.belowbar, color=color.green, text="Rev Long",  textcolor=color.green, size=size.small, title="Long Reversal")
plotshape(i_showSignals and short_signal, style=shape.triangledown, location=location.abovebar, color=color.red,   text="Rev Short", textcolor=color.red,   size=size.small, title="Short Reversal")

// SL/TP reference lines
plot(i_showSLTP and not na(entrySL) ? entrySL : na, "Stop Loss", color=color.new(color.orange, 30), style=plot.style_linebr, linewidth=1)
plot(i_showSLTP and not na(entryTP) ? entryTP : na, "Take Profit", color=color.new(color.lime, 30), style=plot.style_linebr, linewidth=1)
plot(i_showSLTP and not na(entryPrice) ? entryPrice : na, "Entry", color=color.new(color.gray, 50), style=plot.style_linebr, linewidth=1)

// Signal background
bgcolor(long_signal ? color.new(color.green, 90) : short_signal ? color.new(color.red, 90) : na, title="Signal BG")

// Info table
var tbl = table.new(position.top_right, 2, 4, bgcolor=color.new(color.black, 50), border_width=1, border_color=color.new(color.gray, 50))
if i_showInfo and barstate.islast
    table.cell(tbl, 0, 0, "RSI", text_color=color.gray, text_size=size.tiny)
    table.cell(tbl, 1, 0, str.tostring(rsi, "#.0"), text_color=rsi > rsi_overbought ? color.red : rsi < rsi_oversold ? color.green : color.white, text_size=size.tiny)
    table.cell(tbl, 0, 1, "Stoch K", text_color=color.gray, text_size=size.tiny)
    table.cell(tbl, 1, 1, str.tostring(stoch_k_line, "#.0"), text_color=stoch_k_line > stoch_overbought ? color.red : stoch_k_line < stoch_oversold ? color.green : color.white, text_size=size.tiny)
    table.cell(tbl, 0, 2, "ATR", text_color=color.gray, text_size=size.tiny)
    table.cell(tbl, 1, 2, str.tostring(atr, format.mintick), text_color=color.white, text_size=size.tiny)
    statusTxt = not na(entryPrice) ? (isLong ? "LONG" : "SHORT") : "FLAT"
    statusClr = not na(entryPrice) ? (isLong ? color.green : color.red) : color.gray
    table.cell(tbl, 0, 3, "Status", text_color=color.gray, text_size=size.tiny)
    table.cell(tbl, 1, 3, statusTxt, text_color=statusClr, text_size=size.tiny)

// ==================================================================================
// Alert Conditions
// ==================================================================================
alertcondition(long_signal,  "Bullish Reversal",  "RSI oversold + Stoch K/D bullish cross in oversold zone")
alertcondition(short_signal, "Bearish Reversal",  "RSI overbought + Stoch K/D bearish cross in overbought zone")
alertcondition(slHit,        "Stop Loss Hit",     "Price hit the ATR-based stop loss level")
alertcondition(tpHit,        "Take Profit Hit",   "Price hit the ATR-based take profit level")

Overview

On each signal it draws stop loss and take profit lines at an ATR multiple from the signal close, clearing them once price touches either. An optional info table is included. It places no orders. It draws on the price chart.

Details

Published by

rubbermetal on GitHub

Code credit

claygrace74, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Mean reversion, Oscillators & momentum, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

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 Lengthint14rsi_length
RSI Overboughtint70rsi_overbought
RSI Oversoldint30rsi_oversold
Stochastic Lengthint14stoch_length
%K Smoothingint3stoch_k
%D Smoothingint3stoch_d
Stoch Overboughtint80stoch_overbought
Stoch Oversoldint20stoch_oversold
ATR Lengthint14atr_length
ATR Multiplierfloat1.5atr_multiplier
Show Entry Signalsbooltruei_showSignals
Show SL/TP Linesbooltruei_showSLTP
Show all 13 settings
SettingTypeDefaultVariable
Show Info Tablebooltruei_showInfo
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]
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

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]
8 stars

This indicator detects contrarian inflection points and potential market reversals by combining sentiment, volume, and price action metrics directly on the price chart. It evaluates overbought and oversold conditions with the RSI and Stochastic oscillators, hi

Indicator v5 Oscillators & momentumVolatility & bands
Updated 7 weeks ago · None stated GitHub repository of GCR Inflection Point Scanner

Antigravity Elite

by eltonaguiar
4 stars

Antigravity Elite is an overlay indicator that screens price with seven selectable components: Mercury Fear, Connors RSI-2, volatility-spike reversal, EMA stack, Supertrend, multi-sigma bands, and an optional funding proxy. Auto-Detect chooses one method, whil

Indicator v6 Oscillators & momentumMoving averages
Updated yesterday · None stated GitHub repository of Antigravity Elite
4 stars

Calculates Bollinger Bands, RSI, and Stochastic to identify potential reversal opportunities directly on the price chart. It plots buy signals when the bar low is within a set distance of the lower Bollinger Band while both RSI and Stochastic register oversold

Indicator v4 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of RSI and Stoch (Brahim)

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers