Strategy · Pine Script v5 · On the chart

Xsodus RSI Strategy

by xsodus

Xsodus RSI Strategy is a long-only trading script that generates entry signals when the Relative Strength Index (RSI) crosses above a configurable oversold threshold.

View on GitHub

GitHub stars5on the repository
Pine versionv5runs as is
Lines of code71
Settings10inputs
LicenceMIT
Last update2 weeks ago11 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

71 lines of Pine Script v5 from xsodus-rsi-strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

xsodus-rsi-strategy.pine
// SPDX-License-Identifier: MIT
// @version=5
// Author = TradeAutomation


strategy("Xsodus RSI Strategy V1",overlay=true)


// RSI Indicator Calculations //
sourceData = input.source(title="Source Data", defval=close)
rlen  = input.int(title="RSI Length", defval=14, minval=1)
rsi = ta.rsi(close, rlen)
ob = input(70, "Overbought Level")
os = input(30, "Oversold Level")
enableStopLoss = input.bool(title="Enable stop loss", defval=true)
stopLossPercentage =  input.float(title="Stop loss %", defval=20) * 0.01


// Operational Function //
TrendFilterInput = input(false, "Only Trade When Price is Above EMA?")
ema = ta.ema(close, input(100, "EMA Length"))
TrendisLong = (close>ema)
plot(ema)


// Backtest Timeframe Inputs // 
startDate = input.time(title="Start Date",defval=timestamp("2018-01-01T00:00+07:00"))
endDate = input.time(title="End Date", defval=timestamp("9999-01-01T00:00+07:00"))
InDateRange = time > startDate and time < endDate

lastPrice = sourceData[1]

// Global vars
var longStopPrice = 0.0
var isOrdered = false

buy = TrendFilterInput ? ta.crossover(rsi, os) and TrendisLong : ta.crossover(rsi, os)
sell = ta.crossunder(rsi, ob)

// Update stop loss status
if strategy.position_size > 0 and enableStopLoss
    longStopPrice := strategy.position_avg_price * (1 - stopLossPercentage)

if strategy.position_size > 0 and enableStopLoss and longStopPrice > 0.0
    strategy.exit("Long",stop=longStopPrice,comment="Stop loss action")

// Open position 
if strategy.position_size == 0 and InDateRange and isOrdered == false
    strategy.entry("Long", strategy.long, when = buy, comment="Buy")
    isOrdered := buy

// Close position        
if strategy.position_size > 0
    strategy.close("Long", when = sell , comment="Sell")
    
// Reset global states
if  sell
    longStopPrice := 0.0
    isOrdered := false


// Debug in data window
plotchar(sourceData[0], "Current Price", "", location = location.top)
plotchar(lastPrice, "Last Bar Price", "", location = location.top)
plotchar(lastPrice * (1 - stopLossPercentage), "Current Stop Loss Price", "", location = location.top)
plotchar(TrendisLong, "Bullish Trend", "", location = location.top)
plotchar(TrendFilterInput, "Trend Filter Input", "", location = location.top)
plotchar(buy, "Buy?", "", location = location.top)
plotchar(sell, "Sell?", "", location = location.top)
plotchar(isOrdered, "isOrdered?", "", location = location.top)
plotchar(InDateRange, "InDateRange?", "", location = location.top)

Overview

Traders can enable an optional trend filter requiring price to remain above an Exponential Moving Average (EMA). Long positions are closed when RSI crosses below an overbought level or if price hits a percentage-based stop loss. The script plots the EMA directly on the price chart and allows customization of RSI length, thresholds, EMA length, stop-loss percentage, and backtest date range.

Details

Published by

xsodus on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Moving averages, Trend

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.

Topics

pinescript

Settings

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

SettingTypeDefaultVariable
Source DatasourceclosesourceData
RSI Lengthint14rlen
Overbought Levelint70ob
Oversold Levelint30os
Enable stop lossbooltrueenableStopLoss
Stop loss %float20stopLossPercentage
Only Trade When Price is Above EMA?boolfalseTrendFilterInput
EMA Lengthint100EMA Length
Start Datetimetimestamp("2018-01-01T00:00+07:00")startDate
End Datetimetimestamp("9999-01-01T00:00+07:00")endDate
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

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI 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