Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

RSI Mean Reversion Strategy

A Pine Script v5 strategy built on EMA (close, 100) and RSI (close, 14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 9 settings; defaults include EMA Length 100, RSI Oversold Settings 40 and RSI Overbought Settings 60.

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 8 of 8 trades.
How did RSI Mean Reversion Strategy do on BTCUSDT 1D with default settings?
+0.81%
From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
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: 12 before, 20 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 45, 47.
Does RSI Mean Reversion Strategy run in Zeal Terminal?
Yes
It compiles in 13 ms and runs 1,000 bars in 33 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • RSI Lower Band
  • RSI Upper Band
  • 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 (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$1,008,060$2,025,273Equity from $1,000,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. Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 38, 41) so the engine trades the way the script says.
Net profit
+0.81%
$8,060.63
Buy and hold
+102.5%
same period
Closed trades
12
9 won · 3 lost
Profitable
75.0%
of closed trades
Profit factor
3.22
gross profit ÷ gross loss
Max drawdown
0.25%
−$2,510.50

One run with the author's default settings, $1,000,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.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

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

SettingDefaultType and rangeFeeds
Long Entrytrueboolentry Long line 37
Short Entrytrueboolentry Short line 40
EMA Length100intema
RSI Oversold Settings40intOS
RSI Overbought Settings60intOB
Short Take Profit1float · min 0.0 · step 0.1shortExitPrice
Short Stop Loss1.5float · min 0.0 · step 0.1shortStopPrice
Take Profit Percentage
Long Take Profit1float · min 0.0 · step 0.1longExitPrice
Stop Percentage
Long Stop Loss1.5float · min 0.0 · step 0.1longStopPrice

What it calculates

  • EMAclose, EMA Length (100)ema · line 9
  • RSIclose, 14rsi · line 10

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 dataemaSettingsEMA Lengthsetting · 100longProfitPercLong Take Profitsetting · 1shortProfitPercShort Take Profitsetting · 1longStopPercLong Stop Losssetting · 1.5shortStopPercShort Stop Losssetting · 1.5rsiobRSI Overbought Settingssetting · 60rsiosRSI Oversold Settingssetting · 40emaEMA→ emarsiRSI→ rsilongExitPricelongExitPricevalueshortExitPriceshortExitPricevaluelongStopPricelongStopPricevalueshortStopPriceshortStopPricevaluebuySignalbuySignalconditionsellSignalsellSignalconditionuptrend, downtrenduptrend · downtrend2 conditionsOBOBconditionOSOSconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long TP/SLexit Long TP/SLstrategy.exitexit:Short TP/SLexit Short TP/SLstrategy.exitplot:50plotplothline:51hlinehlinehline:52hlinehline

Order rules

OrderFires whenBy defaultLine
Open Long longbuySignal and long_entryOn38
Open Short shortsellSignal and short_entryOn41
Exit Long TP/SL stop and limit(strategy.position_size > 0)On45
Exit Short TP/SL stop and limit(strategy.position_size < 0)On47

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

Does it repaint?

No

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

8/8trades 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+0.8%+102.5%1275%3.220.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.2%+5.5%944%0.620.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.0%+9.8%2352%1.410.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%875%2.270.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%1867%1.470.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%1155%0.710.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%1145%0.360.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%1070%1.580.0%8 May 2026 – 21 Oct 2026

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market2100%$6,032.53
Sideways market560%$72.27
Falling market580%$1,955.83

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

How bad could the drawdown be?

0.3%

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

0%1%
All 12 trades
SideEntryExitBarsP&L
long19 Jun 2024 65,175.3020 Jun 2024 65,827.101$651.76
long21 Jun 2024 64,870.0023 Jun 2024 63,896.902−$973.05
long23 Jun 2025 100,964.0024 Jun 2025 105,334.001$4,370.07
long3 Aug 2025 112,546.004 Aug 2025 114,209.001$1,662.46
short6 Jan 2026 93,859.707 Jan 2026 92,921.101$938.60
short14 Jan 2026 95,414.0015 Jan 2026 96,951.801−$1,537.79
short16 Jan 2026 95,604.8018 Jan 2026 94,648.802$956.05
short17 Mar 2026 74,884.7018 Mar 2026 73,909.401$975.30
short11 Apr 2026 72,962.7012 Apr 2026 72,233.101$729.63
short14 Apr 2026 74,418.0015 Apr 2026 73,673.801$744.18
short16 Apr 2026 74,810.0017 Apr 2026 75,932.101−$1,122.15
short22 Jul 2026 66,556.1023 Jul 2026 65,890.601$665.57

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+0.8%120.2%
RSI Cross [xaurr] by livetrendrsi emav4 strategy+24.4%5335.3%
Bitpanda Coinrule Template by joshuajcoop01rsi emav5 strategy−2.8%44.6%
RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrulersi emav5 strategy−2.8%44.6%
RSI of VWAP by mohaneersi emav4 strategyNo trades on this market
EMA SCALPEUR + RSi - SHORT by YukalMoonrsi emav5 strategyNo trades on this market

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.

  • 5 settings use the untyped input() (line 6, 7, 8, 11, 12). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.bool()
  • Line 7: input() → input.bool()
  • Line 8: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
⋯//Inputs-long_entry = input(true, title='Long Entry')+long_entry = input.bool(true, title='Long Entry')-short_entry = input(true, title='Short Entry')+short_entry = input.bool(true, title='Short Entry')-emaSettings = input(100, 'EMA Length')+emaSettings = input.int(100, 'EMA Length')ema = ta.ema(close,emaSettings)rsi = ta.rsi(close,14)-rsios = input(40, title= 'RSI Oversold Settings')+rsios = input.int(40, title= 'RSI Oversold Settings')-rsiob = input(60, title= 'RSI Overbought Settings')+rsiob = input.int(60, title= 'RSI Overbought Settings')//Conditions⋯

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: 12 before, 20 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.

⋯// © Sarahann999-//@version=5+//@version=6strategy("RSI Strategy", shorttitle="RSI", overlay= false)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 13 msWith a workaround 1,000 bars in 33 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 38, 41) so the engine trades the way the script says.

“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

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Sarahann999//@version=5strategy("RSI Strategy", shorttitle="RSI", overlay= false)//Inputslong_entry = input(true, title='Long Entry')short_entry = input(true, title='Short Entry')emaSettings = input(100, 'EMA Length')ema = ta.ema(close,emaSettings)rsi = ta.rsi(close,14)rsios = input(40, title= 'RSI Oversold Settings')rsiob = input(60, title= 'RSI Overbought Settings')//Conditionsuptrend = close > emadowntrend = close < emaOB = rsi > rsiobOS = rsi < rsiosbuySignal = uptrend and OS and strategy.position_size == 0sellSignal = downtrend and OB and strategy.position_size == 0//Calculate Take Profit PercentagelongProfitPerc = input.float(title="Long Take Profit", group='Take Profit Percentage',     minval=0.0, step=0.1, defval=1) / 100shortProfitPerc = input.float(title="Short Take Profit",     minval=0.0, step=0.1, defval=1) / 100// Figure out take profit price 1longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)// Make inputs that set the stop %  1longStopPerc = input.float(title="Long Stop Loss", group='Stop Percentage',     minval=0.0, step=0.1, defval=1.5) / 100shortStopPerc = input.float(title="Short Stop Loss",     minval=0.0, step=0.1, defval=1.5) / 100// Figure Out Stop PricelongStopPrice  = strategy.position_avg_price * (1 - longStopPerc)shortStopPrice = strategy.position_avg_price * (1 + shortStopPerc)// Submit entry ordersif buySignal and long_entry    strategy.entry(id="Long", direction=strategy.long, alert_message="Enter Long")    if sellSignal and short_entry    strategy.entry(id="Short", direction=strategy.short, alert_message="Enter Short")    //Submit exit orders based on take profit priceif (strategy.position_size > 0)    strategy.exit(id="Long TP/SL", limit=longExitPrice, stop=longStopPrice, alert_message="Long Exit 1 at {{close}}")if (strategy.position_size < 0)    strategy.exit(id="Short TP/SL", limit=shortExitPrice, stop=shortStopPrice, alert_message="Short Exit 1 at {{close}}")    //note: for custom alert messages to read, "{{strategy.order.alert_message}}" must be placed into the alert dialogue box when the alert is set.plot(rsi, color= color.gray)hline(40, "RSI Lower Band")hline(60, "RSI Upper Band")