Pine Script v4 · Strategy
Oversold RSI with tight SL Strategy (by Coinrule)
A Pine Script v4 strategy built on RSI (close, lengthRSI). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 50% of equity and pays 0.1% commission. 10 settings; defaults include From Month 1, From Day 1 and From Year 2020.
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 Oversold RSI with tight SL Strategy (by Coinrule) 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 Oversold RSI with tight SL Strategy (by Coinrule) do on BTCUSDT 1D with default settings?
- −6.12%
- From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Oversold RSI with tight SL Strategy (by Coinrule) 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 Oversold RSI with tight SL Strategy (by Coinrule) use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Oversold RSI with tight SL Strategy (by Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 11 ms and runs 1,000 bars in 39 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −6.12%
- −$61.16
- Buy and hold
- +102.5%
- same period
- Closed trades
- 14
- 4 won · 10 lost
- Profitable
- 28.6%
- of closed trades
- Profit factor
- 0.76
- gross profit ÷ gross loss
- Max drawdown
- 16.34%
- −$173.82
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
1 setting does nothing
“Show Date Range” is declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
3 settings have no label
In the settings dialog oversold (line 21), Stop_loss (line 25), Take_profit (line 26) show an empty name. The labels on this page come from the variable names.
-
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 23, 29. The upgraded version below moves each call inside an if block.
-
Note
Uses long =, which v5 renamed line 23
long = on line 23. v5 writes it as direction = strategy.long or strategy.short.
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.
- 2 strategy calls use the when = argument (line 23, 29). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.integer) → input.int()
- Line 7: input(type = input.integer) → input.int()
- Line 8: input(type = input.integer) → input.int()
- Line 9: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
4 more edits
- Line 11: input(type = input.integer) → input.int()
- Line 12: input(type = input.bool) → input.bool()
- Line 20: rsi → ta.rsi
- Line 23: long = true → direction = strategy.long
⋯// © brodieCoinrule-//@version=4+//@version=5strategy(shorttitle='Oversold RSI with tight SL',title='Oversold RSI with tight SL Strategy (by Coinrule)', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, commission_type=strategy.commission.percent, commission_value=0.1)//Backtest dates-fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)+fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 1970)+fromYear = input.int(defval = 2020, title = "From Year", minval = 1970)-thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)+thruMonth = input.int(defval = 1, title = "Thru Month", minval = 1, maxval = 12)-thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)+thruDay = input.int(defval = 1, title = "Thru Day", minval = 1, maxval = 31)-thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)+thruYear = input.int(defval = 2112, title = "Thru Year", minval = 1970)-showDate = input(defval = true, title = "Show Date Range", type = input.bool)+showDate = input.bool(defval = true, title = "Show Date Range")start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window⋯lengthRSI = 14-RSI = rsi(close, lengthRSI)+RSI = ta.rsi(close, lengthRSI)oversold= input(30)//Entry -strategy.entry(id="long", long = true, when = RSI< oversold and window())+strategy.entry(id="long", direction = strategy.long, when = RSI< oversold and window())//Exit⋯Same 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 21: input() → input.int()
- Line 23: when = RSI< oversold and window() → if block
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 29: when = close < longStopPrice or close > longTakeProfit and window() → if block
⋯RSI = ta.rsi(close, lengthRSI)-oversold= input(30)+oversold= input.int(30)//Entry -strategy.entry(id="long", direction = strategy.long, when = RSI< oversold and window())+if RSI< oversold and window()+ strategy.entry(id="long", direction = strategy.long)//Exit-Stop_loss= ((input (1))/100)+Stop_loss= ((input.int (1))/100)-Take_profit= ((input (7)/100))+Take_profit= ((input.int (7)/100))longStopPrice = strategy.position_avg_price * (1 - Stop_loss)longTakeProfit = strategy.position_avg_price * (1 + Take_profit)-strategy.close("long", when = close < longStopPrice or close > longTakeProfit and window())+if close < longStopPrice or close > longTakeProfit and window()+ strategy.close("long")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: 14 before, 14 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.
⋯// © brodieCoinrule-//@version=5+//@version=6strategy(shorttitle='Oversold RSI with tight SL',title='Oversold RSI with tight SL Strategy (by Coinrule)', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, commission_type=strategy.commission.percent, commission_value=0.1)⋯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 |
|---|---|---|---|
| From Month | 1 | int (written input.integer) · min 1 · max 12 | start |
| From Day | 1 | int (written input.integer) · min 1 · max 31 | start |
| From Year | 2020 | int (written input.integer) · min 1970 | start |
| Thru Month | 1 | int (written input.integer) · min 1 · max 12 | finish |
| Thru Day | 1 | int (written input.integer) · min 1 · max 31 | finish |
| Thru Year | 2112 | int (written input.integer) · min 1970 | finish |
| Show Date Range | true | bool | unused |
| Oversold (no label in the script) | 30 | int | entry long |
| Stop loss (no label in the script) | 1 | int | longStopPrice |
| Take profit (no label in the script) | 7 | int | longTakeProfit |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, lengthRSIRSI · line 20
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 | RSI< oversold and window() | On | 23 |
| Close long | close < longStopPrice or close > longTakeProfit and window() | On | 29 |
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 | −6.1% | +102.5% | 14 | 29% | 0.76 | 16.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −9.4% | +5.5% | 14 | 7% | 0.25 | 10.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +3.2% | +9.8% | 19 | 42% | 1.09 | 17.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −13.6% | +8.4% | 17 | 6% | 0.19 | 13.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −4.4% | +16.7% | 13 | 31% | 0.79 | 14.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −6.3% | +21.5% | 17 | 18% | 0.60 | 12.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +1.4% | +148.3% | 11 | 36% | 1.09 | 13.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.9% | +17.1% | 7 | 29% | 1.57 | 3.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 | 7 | 43% | $62.68 |
| Falling market | 7 | 14% | −$123.84 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
19.7%
The 95th percentile of the worst drawdown when the same 14 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 9.7% to 19.7%; the tick is what actually happened, 15.1%. Order luck alone moves it this much.
All 14 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Jun 2024 60,293.30 | 4 Jul 2024 57,050.00 | 10 | −$27.84 |
| long | 5 Jul 2024 56,628.80 | 7 Jul 2024 55,857.80 | 2 | −$7.58 |
| long | 5 Aug 2024 54,018.80 | 8 Aug 2024 61,686.00 | 3 | $67.35 |
| long | 25 Feb 2025 88,680.40 | 26 Feb 2025 84,250.10 | 1 | −$26.76 |
| long | 27 Feb 2025 84,708.60 | 2 Mar 2025 94,270.00 | 3 | $55.61 |
| long | 17 Nov 2025 92,215.10 | 20 Nov 2025 86,637.20 | 3 | −$33.08 |
| long | 21 Nov 2025 85,129.40 | 27 Nov 2025 91,333.90 | 6 | $36.35 |
| long | 31 Jan 2026 78,741.10 | 1 Feb 2026 76,968.20 | 1 | −$13.02 |
| long | 2 Feb 2026 78,738.60 | 3 Feb 2026 75,770.20 | 1 | −$20.82 |
| long | 4 Feb 2026 73,165.80 | 5 Feb 2026 62,909.90 | 1 | −$73.09 |
| long | 12 Feb 2026 66,272.20 | 23 Feb 2026 64,656.00 | 11 | −$12.60 |
| long | 2 Jun 2026 66,760.80 | 3 Jun 2026 64,142.80 | 1 | −$19.43 |
| long | 4 Jun 2026 63,886.00 | 5 Jun 2026 61,056.50 | 1 | −$21.37 |
| long | 6 Jun 2026 60,884.60 | 14 Jun 2026 65,746.40 | 8 | $35.11 |
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 |
|---|---|---|---|---|---|
| Oversold RSI with tight SL Strategy (by Coinrule) this page | — | v4 strategy | −6.1% | 14 | 16.3% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | With a workaround 1,000 bars in 39 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 23) 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. 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/// © brodieCoinrule//@version=4strategy(shorttitle='Oversold RSI with tight SL',title='Oversold RSI with tight SL Strategy (by Coinrule)', overlay=true, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, commission_type=strategy.commission.percent, commission_value=0.1)//Backtest datesfromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 1970)thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)showDate = input(defval = true, title = "Show Date Range", type = input.bool)start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start windowfinish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish windowwindow() => time >= start and time <= finish ? true : false // create function "within window of time"perc_change(lkb) => overall_change = ((close[0] - close[lkb]) / close[lkb]) * 100// RSI inputs and calculationslengthRSI = 14RSI = rsi(close, lengthRSI)oversold= input(30)//Entry strategy.entry(id="long", long = true, when = RSI< oversold and window())//ExitStop_loss= ((input (1))/100)Take_profit= ((input (7)/100))longStopPrice = strategy.position_avg_price * (1 - Stop_loss)longTakeProfit = strategy.position_avg_price * (1 + Take_profit)strategy.close("long", when = close < longStopPrice or close > longTakeProfit and window())