Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

RSITrendStrategy

A Pine Script v4 strategy built on RSI (close, 5). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 3 settings; defaults include MA 1 5, MA 1 11 and MA 1 6.

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 RSITrendStrategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did RSITrendStrategy do on BTCUSDT 1D with default settings?
+69.19%
From 26 Jan 2024 to 21 Oct 2026, over 22 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can RSITrendStrategy be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does RSITrendStrategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does RSITrendStrategy run in Zeal Terminal?
Yes
It compiles in 7 ms and runs 1,000 bars in 24 ms, in the browser.

BTCUSDT · 1D · default settings

  • HLine
  • HLine
  • Plot
  • Plot
  • Plot
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctHLine$162,325$202,527Equity from $100,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
+69.19%
$69,193.80
Buy and hold
+102.5%
same period
Closed trades
22
17 won · 5 lost
Profitable
77.3%
of closed trades
Profit factor
2.03
gross profit ÷ gross loss
Max drawdown
38.58%
−$45,628.50

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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 stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames rsi → ta.rsi.

v4 → v5

Verified

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

  • Line 5: //@version=4 → //@version=5
  • Line 13: rsi → ta.rsi
  • Line 14: rsi → ta.rsi
  • Line 15: rsi → ta.rsi
⋯//Default value has been taken as 5 and 11, with 6 being used to identify highs & lows.-//@version=4+//@version=5strategy("RSITrendStrategy", overlay=false)⋯///fill(h1, h2, color = color.new(color.blue, 80))-sh = rsi(close, len1)+sh = ta.rsi(close, len1)-ln = rsi(close, len2)+ln = ta.rsi(close, len2)-rs = rsi(close, len3)+rs = ta.rsi(close, len3)p1 = plot(sh, color = color.red)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
⋯strategy("RSITrendStrategy", overlay=false)-len1 = input(title="MA 1", defval = 5)+len1 = input.int(title="MA 1", defval = 5)-len2 = input(title="MA 1", defval = 11)+len2 = input.int(title="MA 1", defval = 11)-len3 = input(title="MA 1", defval = 6)+len3 = input.int(title="MA 1", defval = 6)h1 = hline(30.)⋯

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: 22 before, 35 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.

⋯//Default value has been taken as 5 and 11, with 6 being used to identify highs & lows.-//@version=5+//@version=6strategy("RSITrendStrategy", overlay=false)⋯

Settings

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

SettingDefaultType and rangeFeeds
MA 15intsh
MA 111intln
MA 16intrs

What it calculates

  • RSI (rsi, ta.rsi in v5)close, MA 1 (5)sh · line 13
  • RSI (rsi, ta.rsi in v5)close, MA 1 (11)ln · line 14
  • RSI (rsi, ta.rsi in v5)close, MA 1 (6)rs · 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 datalen1MA 1setting · 5len2MA 1setting · 11len3MA 1setting · 6shRSI→ shlnRSI→ lnrsRSI→ rsbuybuyconditionsellsellconditionmycolColourmycolentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryhline:10hlinehlinehline:11hlinehlineplot:16plotplotplot:17plotplotplot:18plotplotfill:20Fillfill

Order rules

OrderFires whenBy defaultLine
Open long long(buy)On23
Open short short(sell)On26

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.

4/4trades 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+69.2%+102.5%2277%2.0338.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−11.1%+5.5%1753%0.6026.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.5%+9.8%1450%1.652.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%1573%0.970.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.3%+16.7%2176%4.270.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%2167%1.990.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%1258%1.020.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.3%+17.1%1782%3.160.2%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 (MA 1 6, MA 1 9) made +62.7% before 26 Dec 2025 and +42.9% after it, against +42.9% for the defaults. 46% of the 48 combinations made money in-sample and 56% out-of-sample.

Before 26 Dec 2025 · in-sample
MA 1 ↓ · MA 1 →345679
6−14%−14%−37%0%+33%0%
7−8%−28%−36%+16%0%0%
8−11%−29%+17%+26%+46%−9%
9−2%−29%+26%+63%+50%0%
11−21%−30%+26%+50%+44%−34%
13−21%+5%+46%+42%+49%−12%
15−21%+5%+50%+49%−32%−11%
19−29%+25%+32%+41%−12%+32%
From 26 Dec 2025 · out-of-sample
MA 1 ↓ · MA 1 →345679
6−24%−22%−19%0%0%0%
7−24%−19%−19%+43%0%0%
8−22%−19%+44%+43%+43%0%
9−22%−19%+43%+43%+43%0%
11−20%+43%+43%+43%+22%+21%
13−19%+43%+43%+22%+22%+28%
15−19%+43%+43%+22%+21%+28%
19+7%+43%+22%+21%+28%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 market667%$22,433.60
Sideways market1377%$18,405.50
Falling market3100%$28,354.80

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

How bad could the drawdown be?

40.4%

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

0%46%
All 22 trades
SideEntryExitBarsP&L
short18 Feb 2024 51,642.604 May 2024 62,882.0076−$11,239.40
long4 May 2024 62,882.008 Jun 2024 69,355.6035$6,473.59
short8 Jun 2024 69,355.6028 Jun 2024 61,706.5020$7,649.14
long28 Jun 2024 61,706.5024 Jul 2024 65,936.0026$4,229.54
short24 Jul 2024 65,936.009 Aug 2024 61,686.0016$4,250.00
long9 Aug 2024 61,686.0026 Sep 2024 63,152.0048$1,466.01
short26 Sep 2024 63,152.0012 Oct 2024 62,540.0016$612.02
long12 Oct 2024 62,540.0022 Oct 2024 67,377.5010$4,837.51
short22 Oct 2024 67,377.5025 Dec 2024 98,663.6064−$31,286.10
long25 Dec 2024 98,663.608 Jan 2025 96,954.6014−$1,708.98
short8 Jan 2025 96,954.602 Mar 2025 86,064.5053$10,890.10
long2 Mar 2025 86,064.501 May 2025 94,172.0060$8,107.46
short1 May 2025 94,172.0024 Jun 2025 105,334.0054−$11,161.90
long24 Jun 2025 105,334.0016 Jul 2025 117,758.0022$12,424.10
short16 Jul 2025 117,758.0029 Sep 2025 112,164.0075$5,594.12
long29 Sep 2025 112,164.008 Oct 2025 121,333.009$9,169.00
short8 Oct 2025 121,333.008 Nov 2025 103,339.0031$17,993.90
long8 Nov 2025 103,339.008 Jan 2026 91,364.2061−$11,974.90
short8 Jan 2026 91,364.207 Feb 2026 70,580.3030$20,783.90
long7 Feb 2026 70,580.3013 Apr 2026 70,741.6065$161.30
short13 Apr 2026 70,741.608 Jun 2026 63,332.0056$7,409.55
long8 Jun 2026 63,332.0029 Aug 2026 77,845.9082$14,513.90

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
RSITrendStrategy this page—v4 strategy+69.2%2238.6%
Triple RSI strategy by Trade_by_DBrsiv5 strategy+3.2%23.3%
Hobbiecode - RSI + Close previous day by hobbiecodersiv5 strategy+1.2%634.2%
dirt cheap yet elegant RSI Strategy by SparkyFlaryrsiv4 strategy−11.4%820.5%
RSI Classic Strategy (by Coinrule) by Coinrulersiv4 strategy+7.5%67.2%
Cheat Code- Example 1; Short-Term; Follow the Trend by CheatCode1rsiv5 strategy−1.0%25.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 7 msYes 1,000 bars in 24 msNot measured
PineTSNo v5 and v6 only—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. PineTS runs Pine Script v5 and v6 only.

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/// © email_analysts// This code gives indication on the chart to go long or short based on RSI crossover strategy. //Default value has been taken as 5 and 11, with 6 being used to identify highs & lows.//@version=4strategy("RSITrendStrategy", overlay=false)len1 = input(title="MA 1", defval = 5)len2 = input(title="MA 1", defval = 11)len3 = input(title="MA 1", defval = 6)h1 = hline(30.)h2 = hline(70.)///fill(h1, h2, color = color.new(color.blue, 80))sh = rsi(close, len1)ln = rsi(close, len2)rs = rsi(close, len3)p1 = plot(sh, color = color.red)p2 = plot(ln, color = color.green)p3 = plot(rs, color = color.white)mycol = sh > ln ? color.lime : color.redfill(p1, p2, color = mycol)buy = (sh[1] < ln[1] and sh > ln and rs[1] < 30) if (buy)    strategy.entry("long", strategy.long)sell = (sh[1] > ln[1] and sh < ln and rs[1] > 70)if (sell)    strategy.entry("short", strategy.short)