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.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Source Data
source
close
sourceData
RSI Length
int
14
rlen
Overbought Level
int
70
ob
Oversold Level
int
30
os
Enable stop loss
bool
true
enableStopLoss
Stop loss %
float
20
stopLossPercentage
Only Trade When Price is Above EMA?
bool
false
TrendFilterInput
EMA Length
int
100
EMA Length
Start Date
time
timestamp("2018-01-01T00:00+07:00")
startDate
End Date
time
timestamp("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.
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
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
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
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
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
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