Pine Script v5 · Strategy
Reinforced RSI - The Quant Science
A Pine Script v5 strategy built on RSI (close, 14), Crossunder (rsi, 35) and Crossover (rsi, 75). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.07% commission. 6 settings; defaults include RSI lenght: 14, Oversold: 35 and Overbought: 75.
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 Reinforced RSI - The Quant Science repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Reinforced RSI - The Quant Science do on BTCUSDT 1D with default settings?
- −3.94%
- From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Reinforced RSI - The Quant Science run in Pine Script v6?
- Yes
- Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Reinforced RSI - The Quant Science use a stop loss?
- Yes
- strategy.exit sets a stop on line 67.
- Does Reinforced RSI - The Quant Science run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 173 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −3.94%
- −$39.38
- Buy and hold
- +102.5%
- same period
- Closed trades
- 7
- 2 won · 5 lost
- Profitable
- 28.6%
- of closed trades
- Profit factor
- 0.30
- gross profit ÷ gross loss
- Max drawdown
- 3.94%
- −$39.38
One run with the author's default settings, $1,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
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.
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 lenght: | 14 | int · min 1 | rsi |
| Oversold: | 35 | int · min 1 | trigger |
| Overbought: | 75 | int · min 1 | exit |
| Lookback period: | 30 | int · min 0 · max 500 | probabilities |
| Take profit: | 1.00 | float · min 0 | takeprofit |
| Stop loss: | 1.00 | float · min 0 | stoploss |
What it calculates
- RSIclose, length = RSI lenght: (14)
rsi · line 14 - Crossunderrsi, Oversold: (35)
trigger · line 17 - Crossoverrsi, Overbought: (75)
exit · line 18 - ValuewhenLONG, close, 0
p · line 33 - ValuewhenCLOSE_LONG_TP, close, 0
p2 · line 34
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 e long | trigger==true and strategy.opentrades==0 and probabilities >= 51 | On | 60 |
| Exit c limit | exit==true | On | 65 |
| Exit c stop and limit | takeprofit and stoploss | On | 67 |
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.
- 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 | −3.9% | +102.5% | 7 | 29% | 0.30 | 3.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.6% | +5.5% | 3 | 67% | 1.50 | 2.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −9.0% | +9.8% | 17 | 29% | 0.31 | 9.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2.3% | +8.4% | 5 | 80% | 2.95 | 1.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −1.7% | +16.7% | 5 | 40% | 0.50 | 2.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +5.0% | +21.5% | 8 | 88% | 5.29 | 1.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.9% | +148.3% | 13 | 54% | 0.87 | 1.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 7 | 57% | 1.00 | 2.5% | 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 | 0 | — | $0.00 |
| Sideways market | 4 | 25% | −$25.07 |
| Falling market | 3 | 33% | −$14.31 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.6%
The 95th percentile of the worst drawdown when the same 7 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.9% to 5.6%; the tick is what actually happened, 3.9%. Order luck alone moves it this much.
All 7 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Jun 2024 63,210.00 | 24 Jun 2024 62,577.90 | 0 | −$11.39 |
| long | 29 Jun 2024 60,427.80 | 29 Jun 2024 61,032.10 | 0 | $8.50 |
| long | 5 Jul 2024 57,050.00 | 5 Jul 2024 56,479.50 | 0 | −$11.36 |
| long | 8 Jul 2024 55,857.80 | 8 Jul 2024 55,299.20 | 0 | −$11.23 |
| long | 5 Aug 2024 58,161.00 | 5 Aug 2024 57,579.40 | 0 | −$11.10 |
| long | 7 Sep 2024 53,963.00 | 7 Sep 2024 54,502.60 | 0 | $8.28 |
| long | 9 Apr 2025 76,322.40 | 9 Apr 2025 75,559.20 | 0 | −$11.07 |
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 |
|---|---|---|---|---|---|
| Reinforced RSI - The Quant Science this page | — | v5 strategy | −3.9% | 7 | 3.9% |
| RSI+PA+DCA Strategy by A3Sh | rsi valuewhen | v4 strategy | +22.3% | 46 | 5.1% |
| Tendency EMA + RSI [Alorse] by alorse | rsi valuewhen | v5 strategy | +4.3% | 4 | 1.9% |
| Fibonacci + RSI - Strategy by MohamedYAbdelaziz | rsi valuewhen | v4 strategy | +3.4% | 2 | 19.2% |
| Momentum Strategy (BTC-USDT; 30m) - STOCH RSI (with source code) by Drun30 | rsi valuewhen | v4 strategy | +13.3% | 12 | 13.6% |
| Impulse Strategy Signals V2 by danieljordi | rsi valuewhen | v5 strategy | No 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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © thequantscience-//@version=5+//@version=6strategy("Reinforced RSI - The Quant Science",⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | With a workaround 1,000 bars in 173 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 60) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © thequantscience//@version=5strategy("Reinforced RSI - The Quant Science", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 1, currency = currency.EUR, initial_capital = 1000, commission_type = strategy.commission.percent, commission_value = 0.07)lenght_rsi = input.int(defval = 14, minval = 1, title = "RSI lenght: ")rsi = ta.rsi(close, length = lenght_rsi)rsi_value_check_entry = input.int(defval = 35, minval = 1, title = "Oversold: ")rsi_value_check_exit = input.int(defval = 75, minval = 1, title = "Overbought: ")trigger = ta.crossunder(rsi, rsi_value_check_entry)exit = ta.crossover(rsi, rsi_value_check_exit)entry_condition = trigger TPcondition_exit = exitlook = input.int(defval = 30, minval = 0, maxval = 500, title = "Lookback period: ")Probabilities(lookback) => isActiveLong = false isActiveLong := nz(isActiveLong[1], false) isSellLong = false isSellLong := nz(isSellLong[1], false) int positive_results = 0 int negative_results = 0 float positive_percentage_probabilities = 0 float negative_percentage_probabilities = 0 LONG = not isActiveLong and entry_condition == true CLOSE_LONG_TP = not isSellLong and TPcondition_exit == true p = ta.valuewhen(LONG, close, 0) p2 = ta.valuewhen(CLOSE_LONG_TP, close, 0) for i = 1 to lookback if (LONG[i]) isActiveLong := true isSellLong := false if (CLOSE_LONG_TP[i]) isActiveLong := false isSellLong := true if p[i] > p2[i] positive_results += 1 else negative_results += 1 positive_relative_probabilities = positive_results / lookback negative_relative_probabilities = negative_results / lookback positive_percentage_probabilities := positive_relative_probabilities * 100 negative_percentage_probabilities := negative_relative_probabilities * 100 positive_percentage_probabilities probabilities = Probabilities(look) lots = strategy.equity/closevar float e = 0 var float c = 0 tp = input.float(defval = 1.00, minval = 0, title = "Take profit: ")sl = input.float(defval = 1.00, minval = 0, title = "Stop loss: ")if trigger==true and strategy.opentrades==0 and probabilities >= 51 e := close strategy.entry(id = "e", direction = strategy.long, qty = lots, limit = e) takeprofit = e + ((e * tp)/100)stoploss = e - ((e * sl)/100)if exit==true c := close strategy.exit(id = "c", from_entry = "e", limit = c)if takeprofit and stoploss strategy.exit(id = "c", from_entry = "e", stop = stoploss, limit = takeprofit)