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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| RSI length | 2 | int · min 1 | rsi |
| Buy below RSI | 10 | int · min 1 · max 50 | longSetup hline |
| Sell above RSI | 70 | int · min 50 · max 99 | close Long line 25 hline |
| Trend filter length | 200 | int · min 1 | trend |
| Stop loss % | 8.0 | float · min 0.1 · step 0.1 | stopPrice |
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longSetup and strategy.position_size == 0 | On | 20 |
| Exit Stop stop | strategy.position_size > 0 | On | 24 |
| Close Long | rsi > exitLevel | On | 26 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Oversold in an uptrend | alertcondition | RSI is below the buy level with price above the trend average | 32 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2.2% | +102.5% | 16 | 69% | 2.22 | 1.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.1% | +5.5% | 23 | 65% | 1.11 | 0.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +3.2% | +9.8% | 15 | 67% | 1.75 | 1.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.3% | +8.4% | 21 | 67% | 1.29 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −2.0% | +16.7% | 19 | 47% | 0.73 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.0% | +21.5% | 19 | 74% | 1.86 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.9% | +148.3% | 17 | 65% | 1.21 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.2% | +17.1% | 16 | 69% | 0.77 | 0.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.
| Trend filter length ↓ · RSI length → | 1 | 2 | 3 |
|---|---|---|---|
| 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% |
| Trend filter length ↓ · RSI length → | 1 | 2 | 3 |
|---|---|---|---|
| 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 11 | 82% | $268.88 |
| Sideways market | 5 | 40% | −$46.80 |
| Falling market | 0 | — | $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.
All 16 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 Nov 2024 67,850.00 | 7 Nov 2024 75,572.00 | 2 | $112.70 |
| long | 26 Nov 2024 93,010.00 | 30 Nov 2024 97,460.00 | 4 | $47.32 |
| long | 20 Dec 2024 97,461.90 | 25 Dec 2024 98,663.60 | 5 | $11.50 |
| long | 29 Jan 2025 101,336.00 | 30 Jan 2025 103,733.00 | 1 | $23.03 |
| long | 3 Feb 2025 97,700.60 | 11 Feb 2025 97,430.80 | 8 | −$3.83 |
| long | 25 Feb 2025 91,552.90 | 26 Feb 2025 84,228.60 | 1 | −$82.46 |
| long | 27 Feb 2025 84,250.10 | 3 Mar 2025 94,270.00 | 4 | $119.09 |
| long | 30 May 2025 105,590.00 | 3 Jun 2025 105,858.00 | 4 | $1.57 |
| long | 6 Jun 2025 101,509.00 | 8 Jun 2025 105,552.00 | 2 | $39.68 |
| long | 21 Jun 2025 103,298.00 | 24 Jun 2025 105,334.00 | 3 | $19.19 |
| long | 1 Aug 2025 115,764.00 | 5 Aug 2025 115,055.00 | 4 | −$7.32 |
| long | 19 Aug 2025 116,227.00 | 23 Aug 2025 116,936.00 | 4 | $5.24 |
| long | 23 Sep 2025 112,651.00 | 29 Sep 2025 112,164.00 | 6 | −$5.47 |
| long | 11 Oct 2025 112,775.00 | 17 Oct 2025 103,753.00 | 6 | −$83.19 |
| long | 11 Sep 2026 76,568.70 | 15 Sep 2026 78,189.20 | 4 | $20.54 |
| long | 8 Oct 2026 83,321.80 | 12 Oct 2026 83,773.10 | 4 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| RSI Mean Reversion Strategy this page | — | v5 strategy | +2.2% | 16 | 1.6% |
| SRJ RSI Outperformer Strategy by Sapt_Jash | rsi sma | v5 strategy | +0.6% | 8 | 2.4% |
| RSI SMA Crossover Strategy by reees | rsi sma | v5 strategy | +39.8% | 42 | 30.8% |
| Short In Downtrend Below MA100 (Coinrule) by Coinrule | sma rsi | v4 strategy | −34.5% | 99 | 45.4% |
| Simple RSI and SMA Long and Short (by Coinrule) by Coinrule | rsi sma | v5 strategy | −3.0% | 2 | 17.7% |
| Maximized Moving Average Crossing (by Coinrule) by Coinrule | sma rsi | v4 strategy | −6.6% | 9 | 13.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
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | Yes 1,000 bars in 43 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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")