Strategy · Pine Script v6 · Own pane

RSI Reversal

by GammaExpansion

This long-only strategy calculates an RSI and a long exponential moving average.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code38
Settings6inputs
LicenceMIT
Last update5 days ago23 Oct 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

38 lines of Pine Script v6 from apps/web/examples/rsi-reversal.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

rsi-reversal.pine
//@version=6
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 GammaExpansion
// Original OptiPine example: buy an oversold recovery above a long EMA, long only.
strategy("RSI Reversal", overlay = false,
     initial_capital = 100000,
     default_qty_type = strategy.percent_of_equity,
     default_qty_value = 95,
     commission_type = strategy.commission.percent,
     commission_value = 0.1)

length   = input.int(14, "RSI length", minval = 2, maxval = 100)
oversold = input.float(30.0, "Oversold", minval = 10.0, maxval = 45.0, step = 1.0)
src      = input.source(close, "Source")
midline  = input.bool(true, "Exit at midline")
stop     = input.float(10.0, "Stop %", minval = 0.5, maxval = 20.0, step = 0.5, group = "Risk")
trendLength = input.int(200, "Trend EMA length", minval = 50, maxval = 500, step = 10, group = "Filter")

rsi = ta.rsi(src, length)
trend = ta.ema(close, trendLength)
exitLevel = midline ? 50.0 : 100.0 - oversold
buySignal = ta.crossover(rsi, oversold) and strategy.position_size == 0 and close > trend
sellSignal = ta.crossover(rsi, exitLevel) and strategy.position_size > 0

if buySignal
    strategy.entry("L", strategy.long)
if sellSignal
    strategy.close("L")
if strategy.position_size > 0
    strategy.exit("L stop", "L", stop = strategy.position_avg_price * (1 - stop / 100))

plot(rsi, "RSI", color = color.teal, linewidth = 2)
plot(oversold, "Oversold", color = color.gray)
plot(exitLevel, "Exit level", color = color.gray)
plotshape(buySignal, "Buy", style = shape.triangleup,
     location = location.belowbar, color = color.lime, size = size.tiny, force_overlay = true)
plotshape(sellSignal, "Sell", style = shape.triangledown,
     location = location.abovebar, color = color.red, size = size.tiny, force_overlay = true)

Overview

RSI Reversal enters when RSI crosses above the oversold level while price is above the trend average and no position is open. It closes when RSI crosses the midline or a mirrored overbought level, depending on the midline setting. A percentage stop is placed from the average entry price. Position size defaults to a large share of equity. The oscillator plots in a separate pane, while entry and exit markers appear on the price chart.

Details

Published by

GammaExpansion on GitHub

Type

Strategy, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

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 lengthint14length
Oversoldfloat30.0oversold
Sourcesourceclosesrc
Exit at midlinebooltruemidline
Stop %float10.0stop
Trend EMA lengthint200trendLength
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

330 stars

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated today · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

8D Run

by hasnocool
106 stars

8D Run is a Pine Script momentum strategy inspired by Linda Bradford Raschke. It tracks consecutive price closes relative to a 5-period Simple Moving Average (SMA). When price remains above the SMA for 8 or more bars and then dips below it, the strategy enters

Strategy v5 Oscillators & momentumMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 8D Run

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD
25 stars

This Pine Script strategy calculates Bayesian probabilities of price breaking up or down relative to Bollinger Bands and a Simple Moving Average. It plots these breakout and breakdown probability lines as oscillators in a separate pane. Long entries trigger wh

Strategy v4 Oscillators & momentumVolatility & bands
Updated 6 years ago · None stated GitHub repository of Bayesian BBSMA Oscillator Strategy

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy combines Bollinger Bands, Bollinger Band Width, and the Relative Strength Index (RSI) for mean-reversion trades. It enters long when price crosses below the lower band with oversold RSI, or when band width contracts under low volatility. Short en

Strategy v4 Mean reversionOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers