Strategy · Pine Script v6 · On the chart

RSI-2 (Larry Connors) [JR]

by jayadevrana

This mean-reversion strategy implements Larry Connors' 2-period RSI system.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code54
Settings10inputs
LicenceMPL-2.0
Last update2 days ago26 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

54 lines of Pine Script v6 from scripts/larry-connors-rsi-2.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

larry-connors-rsi-2.pine.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JayadevRana
//@version=6
// Larry Connors — the 2-period RSI strategy from "Short Term Trading Strategies That Work" (2008):
// only buy when price is above its 200-day average; buy at the close when RSI(2) drops below 10;
// sell at the close when price closes above its 5-day average. No stop in the original rules.
strategy("RSI-2 (Larry Connors) [JR]", shorttitle = "Connors RSI-2", overlay = true,
     initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
     commission_type = strategy.commission.percent, commission_value = 0.02, slippage = 2,
     margin_long = 0, margin_short = 0, process_orders_on_close = true, pyramiding = 0)

G1 = "1 · Entry"
rsiLen   = input.int(2, "RSI length", minval = 2, group = G1)
buyLvl   = input.float(10, "Buy when RSI below", minval = 1, step = 1, group = G1)
trendLen = input.int(200, "Only long above the N-day average", minval = 20, group = G1)
shortOn  = input.bool(false, "Also short: below average, RSI above 100 − level", group = G1)
G2 = "2 · Exit"
exitLen  = input.int(5, "Exit when close crosses the N-day average", minval = 2, group = G2)
stopPct  = input.float(0.0, "Optional stop % (0 = none, as in the book)", minval = 0, step = 0.5, group = G2)
maxHold  = input.int(0, "Optional max days (0 = none)", minval = 0, group = G2)
G3 = "3 · Test window"
fromT = input.time(timestamp("2000-01-01T00:00:00"), "Trade from", group = G3)
toT   = input.time(timestamp("2100-01-01T00:00:00"), "Trade until", group = G3)
showLv = input.bool(true, "Show averages", group = G3)

inWin = time >= fromT and time <= toT
r     = ta.rsi(close, rsiLen)
trend = ta.sma(close, trendLen)
exitM = ta.sma(close, exitLen)
var int entryBar = na
if strategy.position_size != 0 and strategy.position_size[1] == 0
    entryBar := bar_index

if strategy.position_size == 0 and inWin
    if close > trend and r < buyLvl
        strategy.entry("RSI2 L", strategy.long)
    else if shortOn and close < trend and r > 100 - buyLvl
        strategy.entry("RSI2 S", strategy.short)
if strategy.position_size > 0
    if close > exitM or (maxHold > 0 and bar_index - entryBar >= maxHold)
        strategy.close("RSI2 L", comment = "exit")
    if stopPct > 0
        strategy.exit("RSI2 L stop", "RSI2 L", stop = strategy.position_avg_price * (1 - stopPct / 100))
if strategy.position_size < 0
    if close < exitM or (maxHold > 0 and bar_index - entryBar >= maxHold)
        strategy.close("RSI2 S", comment = "exit")
    if stopPct > 0
        strategy.exit("RSI2 S stop", "RSI2 S", stop = strategy.position_avg_price * (1 + stopPct / 100))
if not inWin and strategy.position_size != 0
    strategy.close_all(comment = "window end")

plot(showLv ? trend : na, "Trend average", color.new(color.blue, 0), 2)
plot(showLv ? exitM : na, "Exit average", color.new(color.orange, 0), 1)
plotshape(showLv and strategy.position_size == 0 and close > trend and r < buyLvl, "RSI(2) oversold above trend", shape.triangleup, location.belowbar, color.new(color.teal, 0), size = size.tiny)

Overview

RSI-2 (Larry Connors) [JR] enters long positions when price trades above a long-term simple moving average (default 200) and the 2-period RSI drops below 10. Optional short positions enter below the trend average when RSI is overbought. Positions exit when price crosses a short-term moving average (default 5), reaches an optional maximum holding period, or hits an optional percentage stop loss. It plots the trend and exit moving averages directly on the price chart. By default, no stop loss is active.

Details

Published by

jayadevrana on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Mean reversion, Oscillators & momentum, Trend, Moving averages

Markets

Stocks, Indices

Timeframes

H4 and above, M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingema-crossoverpine-scriptpine-script-v6pinescriptrsitechnical-analysistrading-automationtrading-indicators

Settings

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

SettingTypeDefaultVariable
RSI lengthint2rsiLen
Buy when RSI belowfloat10buyLvl
Only long above the N-day averageint200trendLen
Also short: below average, RSI above 100 − levelboolfalseshortOn
Exit when close crosses the N-day averageint5exitLen
Optional stop % (0 = none, as in the book)float0.0stopPct
Optional max days (0 = none)int0maxHold
Trade fromtimetimestamp("2000-01-01T00:00:00")fromT
Trade untiltimetimestamp("2100-01-01T00:00:00")toT
Show averagesbooltrueshowLv
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

106 stars

This trend-following strategy identifies buying opportunities during bullish pullbacks on the price chart. It defines a bull market when the 50-period simple moving average trades above the 200-period moving average. Long entries trigger when the RSI drops bel

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of Buy The Dips in Bull Market
4 stars

This strategy trades pullbacks in the direction of a moving-average trend and draws on the price chart. An uptrend requires the 50-period EMA above the 200-period EMA with price above the slower average, and a downtrend is the reverse. It enters long or short

Strategy v6 TrendOscillators & momentum
4 stars

This strategy executes mean-reversion trades based on RSI overbought and oversold levels directly on the price chart. It generates long signals when the RSI crosses back above the oversold boundary and short signals when it crosses below the overbought boundar

Strategy v5 Mean reversionOscillators & momentum
Updated 11 months ago · Custom licence GitHub repository of RSI Mean Reversion Strategy [Lab]
3 stars

The Buy/Sell Position Strategy combines a long-term Exponential Moving Average (EMA) with a short-term Relative Strength Index (RSI) to capture pullbacks in an uptrend. It enters a long position on the price chart when the price is above the EMA filter and the

Strategy v5 TrendOscillators & momentum
Updated 4 months ago · None stated GitHub repository of Buy/Sell Position Strategy

Calculates a long-term Exponential Moving Average as a baseline for fair value alongside a Relative Strength Index. Generates long entry signals when the close price trades at least five percent below the moving average while the RSI is oversold. Exits trades

Strategy v6 TrendOscillators & momentum
Updated 1 year ago · MIT GitHub repository of Buffett-Inspired Value 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