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
- 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
VerifiedSame 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)⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| MA 1 | 5 | int | sh |
| MA 1 | 11 | int | ln |
| MA 1 | 6 | int | rs |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, MA 1 (5)sh · line 13 - RSI (
rsi,ta.rsiin v5)close, MA 1 (11)ln · line 14 - RSI (
rsi,ta.rsiin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | (buy) | On | 23 |
| Open short short | (sell) | On | 26 |
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.
- 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 | +69.2% | +102.5% | 22 | 77% | 2.03 | 38.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −11.1% | +5.5% | 17 | 53% | 0.60 | 26.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.5% | +9.8% | 14 | 50% | 1.65 | 2.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 15 | 73% | 0.97 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.3% | +16.7% | 21 | 76% | 4.27 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 21 | 67% | 1.99 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 12 | 58% | 1.02 | 0.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.3% | +17.1% | 17 | 82% | 3.16 | 0.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.
| MA 1 ↓ · MA 1 → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 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% |
| MA 1 ↓ · MA 1 → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 6 | 67% | $22,433.60 |
| Sideways market | 13 | 77% | $18,405.50 |
| Falling market | 3 | 100% | $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.
All 22 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 18 Feb 2024 51,642.60 | 4 May 2024 62,882.00 | 76 | −$11,239.40 |
| long | 4 May 2024 62,882.00 | 8 Jun 2024 69,355.60 | 35 | $6,473.59 |
| short | 8 Jun 2024 69,355.60 | 28 Jun 2024 61,706.50 | 20 | $7,649.14 |
| long | 28 Jun 2024 61,706.50 | 24 Jul 2024 65,936.00 | 26 | $4,229.54 |
| short | 24 Jul 2024 65,936.00 | 9 Aug 2024 61,686.00 | 16 | $4,250.00 |
| long | 9 Aug 2024 61,686.00 | 26 Sep 2024 63,152.00 | 48 | $1,466.01 |
| short | 26 Sep 2024 63,152.00 | 12 Oct 2024 62,540.00 | 16 | $612.02 |
| long | 12 Oct 2024 62,540.00 | 22 Oct 2024 67,377.50 | 10 | $4,837.51 |
| short | 22 Oct 2024 67,377.50 | 25 Dec 2024 98,663.60 | 64 | −$31,286.10 |
| long | 25 Dec 2024 98,663.60 | 8 Jan 2025 96,954.60 | 14 | −$1,708.98 |
| short | 8 Jan 2025 96,954.60 | 2 Mar 2025 86,064.50 | 53 | $10,890.10 |
| long | 2 Mar 2025 86,064.50 | 1 May 2025 94,172.00 | 60 | $8,107.46 |
| short | 1 May 2025 94,172.00 | 24 Jun 2025 105,334.00 | 54 | −$11,161.90 |
| long | 24 Jun 2025 105,334.00 | 16 Jul 2025 117,758.00 | 22 | $12,424.10 |
| short | 16 Jul 2025 117,758.00 | 29 Sep 2025 112,164.00 | 75 | $5,594.12 |
| long | 29 Sep 2025 112,164.00 | 8 Oct 2025 121,333.00 | 9 | $9,169.00 |
| short | 8 Oct 2025 121,333.00 | 8 Nov 2025 103,339.00 | 31 | $17,993.90 |
| long | 8 Nov 2025 103,339.00 | 8 Jan 2026 91,364.20 | 61 | −$11,974.90 |
| short | 8 Jan 2026 91,364.20 | 7 Feb 2026 70,580.30 | 30 | $20,783.90 |
| long | 7 Feb 2026 70,580.30 | 13 Apr 2026 70,741.60 | 65 | $161.30 |
| short | 13 Apr 2026 70,741.60 | 8 Jun 2026 63,332.00 | 56 | $7,409.55 |
| long | 8 Jun 2026 63,332.00 | 29 Aug 2026 77,845.90 | 82 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| RSITrendStrategy this page | — | v4 strategy | +69.2% | 22 | 38.6% |
| Triple RSI strategy by Trade_by_DB | rsi | v5 strategy | +3.2% | 2 | 3.3% |
| Hobbiecode - RSI + Close previous day by hobbiecode | rsi | v5 strategy | +1.2% | 63 | 4.2% |
| dirt cheap yet elegant RSI Strategy by SparkyFlary | rsi | v4 strategy | −11.4% | 8 | 20.5% |
| RSI Classic Strategy (by Coinrule) by Coinrule | rsi | v4 strategy | +7.5% | 6 | 7.2% |
| Cheat Code- Example 1; Short-Term; Follow the Trend by CheatCode1 | rsi | v5 strategy | −1.0% | 2 | 5.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 7 ms | Yes 1,000 bars in 24 ms | Not measured |
| PineTS | No 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)