Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

RSI Mean Reversion Strategy

A Pine Script v5 strategy built on RSI (close, 2) and SMA (close, 200). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 10% of equity and pays 0.05% commission. 5 settings; defaults include RSI length 2, Buy below RSI 10 and Sell above RSI 70.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does RSI Mean Reversion Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did RSI Mean Reversion Strategy do on BTCUSDT 1D with default settings?
+2.22%
From 26 Jan 2024 to 21 Oct 2026, over 16 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does RSI Mean Reversion Strategy have?
1
Oversold in an uptrend.
Does RSI Mean Reversion Strategy run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 16 before, 16 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does RSI Mean Reversion Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 24.

BTCUSDT · 1D · default settings

  • RSI
  • Buy level
  • Sell level
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctRSI$10,222$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+2.22%
$222.09
Buy and hold
+102.5%
same period
Closed trades
16
11 won · 5 lost
Profitable
68.8%
of closed trades
Profit factor
2.22
gross profit ÷ gross loss
Max drawdown
1.56%
−$158.65

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

Nothing to point out.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
RSI length2int · min 1rsi
Buy below RSI10int · min 1 · max 50longSetup hline
Sell above RSI70int · min 50 · max 99close Long line 25 hline
Trend filter length200int · min 1trend
Stop loss %8.0float · min 0.1 · step 0.1stopPrice

What it calculates

  • RSIclose, RSI length (2)rsi · line 14
  • SMAclose, Trend filter length (200)trend · line 15

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datarsiLenRSI lengthsetting · 2trendLenTrend filter lengthsetting · 200stopPctStop loss %setting · 8.0entryLevelBuy below RSIsetting · 10exitLevelSell above RSIsetting · 70rsiRSI→ rsitrendSMA→ trendstopPricestopPricevaluelongSetuplongSetupconditionentry:LongOpen Longstrategy.entryexit:Stopexit Stopstrategy.exitclose:LongClose Longstrategy.closeplot:28RSIplothline:29hlinehlinehline:30hlinehlinealertcondition:32Oversold in an uptrendalertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longlongSetup and strategy.position_size == 0On20
Exit Stop stopstrategy.position_size > 0On24
Close Longrsi > exitLevelOn26

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Oversold in an uptrendalertconditionRSI is below the buy level with price above the trend average32

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+2.2%+102.5%1669%2.221.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.1%+5.5%2365%1.110.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+3.2%+9.8%1567%1.751.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%2167%1.290.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−2.0%+16.7%1947%0.732.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.0%+21.5%1974%1.860.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.9%+148.3%1765%1.212.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.2%+17.1%1669%0.770.8%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (RSI length 2, Trend filter length 280) made +3.3% before 26 Dec 2025 and +0.3% after it, against +0.3% for the defaults. 71% of the 24 combinations made money in-sample and 58% out-of-sample.

Before 26 Dec 2025 · in-sample
Trend filter length ↓ · RSI length →123
100+2%+1%+2%
120+0%+1%+2%
140−1%−0%+1%
170−1%−0%+1%
200−1%+2%+2%
240−0%+3%+2%
280+1%+3%+2%
340−1%+2%+2%
From 26 Dec 2025 · out-of-sample
Trend filter length ↓ · RSI length →123
100+0%−1%0%
120+0%−1%0%
140+1%+0%0%
170+1%+0%0%
200+1%+0%0%
240+1%+0%0%
280+1%+0%0%
340+1%+0%0%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1182%$268.88
Sideways market540%−$46.80
Falling market0—$0.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

1.7%

The 95th percentile of the worst drawdown when the same 16 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.8% to 1.7%; the tick is what actually happened, 0.9%. Order luck alone moves it this much.

0%2%
All 16 trades
SideEntryExitBarsP&L
long5 Nov 2024 67,850.007 Nov 2024 75,572.002$112.70
long26 Nov 2024 93,010.0030 Nov 2024 97,460.004$47.32
long20 Dec 2024 97,461.9025 Dec 2024 98,663.605$11.50
long29 Jan 2025 101,336.0030 Jan 2025 103,733.001$23.03
long3 Feb 2025 97,700.6011 Feb 2025 97,430.808−$3.83
long25 Feb 2025 91,552.9026 Feb 2025 84,228.601−$82.46
long27 Feb 2025 84,250.103 Mar 2025 94,270.004$119.09
long30 May 2025 105,590.003 Jun 2025 105,858.004$1.57
long6 Jun 2025 101,509.008 Jun 2025 105,552.002$39.68
long21 Jun 2025 103,298.0024 Jun 2025 105,334.003$19.19
long1 Aug 2025 115,764.005 Aug 2025 115,055.004−$7.32
long19 Aug 2025 116,227.0023 Aug 2025 116,936.004$5.24
long23 Sep 2025 112,651.0029 Sep 2025 112,164.006−$5.47
long11 Oct 2025 112,775.0017 Oct 2025 103,753.006−$83.19
long11 Sep 2026 76,568.7015 Sep 2026 78,189.204$20.54
long8 Oct 2026 83,321.8012 Oct 2026 83,773.104$4.51

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
RSI Mean Reversion Strategy this page—v5 strategy+2.2%161.6%
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%
RSI SMA Crossover Strategy by reeesrsi smav5 strategy+39.8%4230.8%
Short In Downtrend Below MA100 (Coinrule) by Coinrulesma rsiv4 strategy−34.5%9945.4%
Simple RSI and SMA Long and Short (by Coinrule) by Coinrulersi smav5 strategy−3.0%217.7%
Maximized Moving Average Crossing (by Coinrule) by Coinrulesma rsiv4 strategy−6.6%913.3%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 16 before, 16 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © Zeal Terminal-//@version=5+//@version=6strategy("RSI Mean Reversion Strategy", shorttitle = "RSI Reversion", overlay = false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msYes 1,000 bars in 43 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Written by Zeal Terminal and published under the Mozilla Public License 2.0.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5strategy("RSI Mean Reversion Strategy", shorttitle = "RSI Reversion", overlay = false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. Buys when RSI is oversold while price holds above a// long trend average, and sells when RSI recovers or the stop is hit.rsiLen     = input.int(2, "RSI length", minval = 1)entryLevel = input.int(10, "Buy below RSI", minval = 1, maxval = 50)exitLevel  = input.int(70, "Sell above RSI", minval = 50, maxval = 99)trendLen   = input.int(200, "Trend filter length", minval = 1)stopPct    = input.float(8.0, "Stop loss %", minval = 0.1, step = 0.1) rsi   = ta.rsi(close, rsiLen)trend = ta.sma(close, trendLen) longSetup = rsi < entryLevel and close > trend if longSetup and strategy.position_size == 0    strategy.entry("Long", strategy.long) if strategy.position_size > 0    stopPrice = strategy.position_avg_price * (1 - stopPct / 100)    strategy.exit("Stop", "Long", stop = stopPrice)    if rsi > exitLevel        strategy.close("Long", comment = "RSI exit") plot(rsi, "RSI", color = #7e57c2, linewidth = 2)hline(entryLevel, "Buy level", color = color.new(#26a69a, 40))hline(exitLevel, "Sell level", color = color.new(#ef5350, 40)) alertcondition(longSetup, "Oversold in an uptrend", "RSI is below the buy level with price above the trend average")