Pine Script v5 · Strategy
R3 ETF Strategy
A Pine Script v5 strategy built on RSI (close, 2) and Crossover (RSI, 70). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.0035 commission. 8 settings; defaults include RSI Length 2, Today's Min RSI for Entry 10 and Exit 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 R3 ETF Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
- How did R3 ETF Strategy do on BTCUSDT 1D with default settings?
- +17.26%
- From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does R3 ETF 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: 25 before, 50 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 R3 ETF Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does R3 ETF Strategy run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 32 ms, in the browser.
BTCUSDT · 1D · default settings
- 200 Day EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +17.26%
- $172,587.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 25
- 17 won · 8 lost
- Profitable
- 68.0%
- of closed trades
- Profit factor
- 1.33
- gross profit ÷ gross loss
- Max drawdown
- 31.40%
- −$476,724.00
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 stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 30. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Start Time | timestamp('01 Jan 2010 05:00 +0000') | time | InDateRange |
| End Time | timestamp('01 Jan 2099 00:00 +0000') | time | InDateRange |
| RSI Length | 2 | int | RSI |
| Today's Min RSI for EntryThe RSI must be below this number today to qualify for trade entry | 10 | int | Rule2 |
| Exit RSIThe strategy will sell when the RSI crosses over this number | 70 | int | Exit |
| Max RSI 3 Days Ago for EntryThe RSI must be below this number 3 days ago to qualify for trade entry | 60 | int | Rule2 |
| Only enter trades when above qualifier EMA?When this is selected, a trade will only be entered when the price is above the EMA qualifier line. | false | bool | entry Long entry Long line 25 line 27 |
| EMA Trade Qualifier Length | 200 | int | Rule1 200 Day EMA |
What it calculates
- RSIclose, RSI Length (2)
RSI · line 11 - CrossoverRSI, Exit RSI (70)
Exit · line 21
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 | (InDateRange and Rule1 and Rule2 and Rule3 and EMAQualInput==true) | On | 26 |
| Open Long long | (InDateRange and Rule2 and Rule3 and EMAQualInput==false) | On | 28 |
| Close Long | Exit | On | 30 |
| Close | (not InDateRange) | On | 32 |
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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +17.3% | +102.5% | 25 | 68% | 1.33 | 31.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −7.3% | +5.5% | 23 | 65% | 0.60 | 18.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +19.9% | +9.8% | 21 | 67% | 1.28 | 39.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −11.8% | +8.4% | 17 | 65% | 0.50 | 23.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +11.4% | +16.7% | 28 | 61% | 1.12 | 36.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1.1% | +21.5% | 24 | 75% | 0.95 | 22.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +58.1% | +148.3% | 30 | 77% | 2.06 | 28.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −9.8% | +17.1% | 20 | 75% | 0.51 | 16.1% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 8 | 75% | $285,134.00 |
| Sideways market | 10 | 70% | −$15,768.90 |
| Falling market | 7 | 57% | −$96,778.60 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
27.1%
The 95th percentile of the worst drawdown when the same 25 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 13.4% to 27.1%; the tick is what actually happened, 26.2%. Order luck alone moves it this much.
All 25 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 28 Apr 2024 63,118.60 | 3 May 2024 62,882.00 | 5 | −$3,748.77 |
| long | 19 Jun 2024 64,974.40 | 30 Jun 2024 62,772.00 | 11 | −$33,768.90 |
| long | 5 Jul 2024 56,628.80 | 9 Jul 2024 58,050.00 | 4 | $24,155.30 |
| long | 4 Aug 2024 58,161.00 | 8 Aug 2024 61,686.00 | 4 | $59,797.50 |
| long | 1 Sep 2024 57,301.90 | 9 Sep 2024 57,042.00 | 8 | −$4,745.64 |
| long | 2 Oct 2024 60,649.30 | 4 Oct 2024 62,086.00 | 2 | $24,676.40 |
| long | 10 Oct 2024 60,326.40 | 11 Oct 2024 62,540.00 | 1 | $39,129.00 |
| long | 4 Nov 2024 67,850.00 | 6 Nov 2024 75,572.00 | 2 | $125,816.00 |
| long | 23 Dec 2024 94,881.50 | 24 Dec 2024 98,663.60 | 1 | $49,081.70 |
| long | 25 Feb 2025 88,680.40 | 2 Mar 2025 94,270.00 | 5 | $80,704.10 |
| long | 9 Mar 2025 80,734.40 | 15 Mar 2025 84,338.40 | 6 | $60,760.70 |
| long | 30 May 2025 103,985.00 | 2 Jun 2025 105,858.00 | 3 | $25,603.90 |
| long | 21 Jun 2025 102,120.00 | 23 Jun 2025 105,334.00 | 2 | $45,554.40 |
| long | 31 Jul 2025 115,764.00 | 4 Aug 2025 115,055.00 | 4 | −$9,144.75 |
| long | 23 Sep 2025 111,999.00 | 28 Sep 2025 112,164.00 | 5 | $2,187.98 |
| long | 16 Oct 2025 108,194.00 | 20 Oct 2025 110,532.00 | 4 | $32,109.90 |
| long | 14 Nov 2025 94,594.00 | 24 Nov 2025 88,300.00 | 10 | −$101,014.00 |
| long | 15 Dec 2025 86,432.10 | 19 Dec 2025 88,136.90 | 4 | $27,953.00 |
| long | 19 Jan 2026 92,631.00 | 27 Jan 2026 89,250.00 | 8 | −$52,746.00 |
| long | 1 Feb 2026 76,968.20 | 13 Feb 2026 68,854.00 | 12 | −$146,788.00 |
| long | 29 Mar 2026 66,010.90 | 31 Mar 2026 68,284.50 | 2 | $42,899.90 |
| long | 18 May 2026 77,001.90 | 25 May 2026 77,322.00 | 7 | $5,356.79 |
| long | 29 May 2026 73,460.80 | 11 Jun 2026 63,626.00 | 13 | −$173,216.00 |
| long | 10 Sep 2026 76,568.70 | 14 Sep 2026 78,189.20 | 4 | $23,716.40 |
| long | 8 Oct 2026 81,754.40 | 11 Oct 2026 83,773.10 | 3 | $28,255.60 |
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 |
|---|---|---|---|---|---|
| R3 ETF Strategy this page | — | v5 strategy | +17.3% | 25 | 31.4% |
| 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% |
| RSITrendStrategy by email_analysts | rsi | v4 strategy | +69.2% | 22 | 38.6% |
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.
- 1 strategy call uses the when = argument (line 30). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 30: when = Exit → if block
⋯if (InDateRange)- strategy.close("Long", when = Exit, alert_message="Close Long")+ if Exit+ strategy.close("Long", alert_message="Close Long")if (not InDateRange)⋯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: 25 before, 50 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version = 5+// @version = 6// Author = TradeAutomation⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 32 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
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/// @version = 5// Author = TradeAutomationstrategy(title="R3 ETF Strategy", shorttitle="R3 ETF Strategy", process_orders_on_close=true, overlay=true, commission_type=strategy.commission.cash_per_contract, commission_value=0.0035, initial_capital = 1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Backtest Date Range Inputs // StartTime = input.time(defval=timestamp('01 Jan 2010 05:00 +0000'), title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), title='End Time')InDateRange = time>=StartTime and time<=EndTime// Calculations and Inputs //RSILen = input.int(2, "RSI Length")RSI = ta.rsi(close, RSILen)TodaysMinRSI = input.int(10, "Today's Min RSI for Entry", tooltip = "The RSI must be below this number today to qualify for trade entry")ExitRSI = input.int(70, "Exit RSI", tooltip = "The strategy will sell when the RSI crosses over this number")Day3RSIMax = input.int(60, "Max RSI 3 Days Ago for Entry", tooltip = "The RSI must be below this number 3 days ago to qualify for trade entry")EMAQualInput = input.bool(false, "Only enter trades when above qualifier EMA?", tooltip="When this is selected, a trade will only be entered when the price is above the EMA qualifier line.")QEMA = ta.ema(close, input.int(200, "EMA Trade Qualifier Length"))// Strategy Rules //Rule1 = close>QEMARule2 = RSI[3]<Day3RSIMax and RSI<TodaysMinRSIRule3 = RSI<RSI[1] and RSI[1]<RSI[2] and RSI[2]<RSI[3] Exit = ta.crossover(RSI, ExitRSI)// Plot //plot(QEMA, "200 Day EMA")// Entry & Exit Functions //if (InDateRange and Rule1 and Rule2 and Rule3 and EMAQualInput==true) strategy.entry("Long", strategy.long, alert_message="Long")if (InDateRange and Rule2 and Rule3 and EMAQualInput==false) strategy.entry("Long", strategy.long, alert_message="Long")if (InDateRange) strategy.close("Long", when = Exit, alert_message="Close Long")if (not InDateRange) strategy.close_all(alert_message="Out of Date Range")