Strategy · Pine Script v5 · Own pane

RSI Strategy

by vanAmsen

The RSI Strategy plots the Relative Strength Index (RSI) on the chart with oversold and overbought level lines.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code34
Settings5inputs
LicenceGPL-3.0
Last update1 year ago14 Aug 2025

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

34 lines of Pine Script v5 from strategy/rsi.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

rsi.pine
//@version=5 
strategy(title="RSI Strategy", overlay=false, shorttitle="RSI", initial_capital = 10000, 
     default_qty_type = strategy.percent_of_equity, default_qty_value = 100) 

rsi_period = input(14, title="RSI Period") 

rsi_oversold = input(30, title="RSI Oversold Threshold") 
rsi_overbought = input(70, title="RSI Overbought Threshold") 
 
tradeLong = input(true, title="Trade Long") 
tradeShort = input(false, title="Trade Short") 
 
rsi_value = ta.rsi(close, rsi_period) 
 
enter_long = ta.crossover(rsi_value, rsi_oversold) 
exit_long = ta.crossunder(rsi_value, rsi_overbought) 
enter_short = ta.crossunder(rsi_value, rsi_overbought) 
exit_short = ta.crossover(rsi_value, rsi_oversold) 
 
plot(rsi_value, title="RSI", color=color.blue) 
hline(rsi_overbought, "Overbought Level", color=color.red) 
hline(rsi_oversold, "Oversold Level", color=color.green) 
 
if (tradeLong and enter_long) 
    strategy.entry("Long", strategy.long) 

if (tradeLong and exit_long) 
    strategy.close("Long") 

if (tradeShort and enter_short) 
    strategy.entry("Short", strategy.short) 

if (tradeShort and exit_short) 
    strategy.close("Short")

Overview

Long entries trigger when RSI crosses above the oversold threshold, and short entries when it crosses below the overbought threshold. Positions exit on the opposite crossover. Settings include RSI period, oversold/overbought levels, and trade long/short options. It draws in a separate pane and uses percentage of equity position sizing without stop loss.

Details

Published by

vanAmsen on GitHub

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
RSI Periodint14rsi_period
RSI Oversold Thresholdint30rsi_oversold
RSI Overbought Thresholdint70rsi_overbought
Trade LongbooltruetradeLong
Trade ShortboolfalsetradeShort
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]

Q-Trend + KVO Strategy

by TradersPost
228 stars

This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und

Strategy v6 TrendVolume
Updated 3 months ago · None stated GitHub repository of Q-Trend + KVO Strategy

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 2 days ago · Apache-2.0 GitHub repository of MACD Crossover (tutorial)
114 stars

This strategy estimates price behavior using ordinary least squares regression between higher-timeframe data and a generated dataset, smoothed by a Karobein oscillator. It enters long positions when the oscillator turns upward and short positions when it turns

Strategy v4 Oscillators & momentumAI / machine learning Repaints

2xTP, SL to Entry

by hasnocool
106 stars

This strategy executes mean-reversion trades based on Bollinger Bands and the Stochastic Oscillator. Long orders trigger when price dips below the lower band alongside a bullish Stochastic crossover, with an optional oversold threshold. Short orders execute on

Strategy v5 Mean reversionOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 2xTP, SL to Entry
65 stars

This strategy calculates a 20-period Relative Strength Index (RSI) and generates entry orders based on crossovers and crossunders of the 50 level. When RSI crosses above 50, it places a long stop entry at the current high price with a custom alert message. Whe

Strategy v4 Oscillators & momentum
Updated 6 days ago · GPL-3.0 GitHub repository of Strategy Using Alert Message

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