Pine Script v4 · Strategy
Optimized RSI Strategy - Buy The Dips (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 30% 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 Optimized RSI Strategy - Buy The Dips (by Coinrule) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did Optimized RSI Strategy - Buy The Dips (by Coinrule) do on BTCUSDT 1D with default settings?
- −0.22%
- From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Optimized RSI Strategy - Buy The Dips (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 Optimized RSI Strategy - Buy The Dips (by Coinrule) use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Optimized RSI Strategy - Buy The Dips (by Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 8 ms and runs 1,000 bars in 31 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.22%
- −$2.21
- Buy and hold
- +102.5%
- same period
- Closed trades
- 6
- 3 won · 3 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 0.96
- gross profit ÷ gross loss
- Max drawdown
- 10.87%
- −$115.20
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
1 setting has no label
In the settings dialog movingaverage_signal (line 22) shows 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 24, 27. The upgraded version below moves each call inside an if block.
-
Note
Uses long =, which v5 renamed line 24
long = on line 24. 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, sma → ta.sma.
- 2 strategy calls use the when = argument (line 24, 27). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 6 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()
5 more edits
- Line 11: input(type = input.integer) → input.int()
- Line 12: input(type = input.bool) → input.bool()
- Line 18: rsi → ta.rsi
- Line 22: sma → ta.sma
- Line 24: long = true → direction = strategy.long
⋯// © Coinrule-//@version=4+//@version=5strategy(shorttitle='Optimized RSI Strategy',title='Optimized RSI Strategy - Buy The Dips (by Coinrule)', overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_type = strategy.percent_of_equity, default_qty_value = 30, 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)RSI_entry = input(35, title = 'RSI Entry', minval=1)⋯//Calculate Moving Averages-movingaverage_signal = sma(close, input(100))+movingaverage_signal = ta.sma(close, input(100))//Entry -strategy.entry(id="long", long = true, when = RSI< RSI_entry and close < movingaverage_signal and window())+strategy.entry(id="long", direction = strategy.long, when = RSI< RSI_entry and close < movingaverage_signal and window())//Exit⋯Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 22: input() → input.int()
- Line 24: when = RSI< RSI_entry and close < movingaverage_signal and window() → if block
- Line 27: when = RSI > RSI_exit and window() → if block
⋯RSI = ta.rsi(close, lengthRSI)-RSI_entry = input(35, title = 'RSI Entry', minval=1)+RSI_entry = input.int(35, title = 'RSI Entry', minval=1)-RSI_exit = input(65, title = 'RSI Close', minval=1)+RSI_exit = input.int(65, title = 'RSI Close', minval=1)//Calculate Moving Averages-movingaverage_signal = ta.sma(close, input(100))+movingaverage_signal = ta.sma(close, input.int(100))//Entry -strategy.entry(id="long", direction = strategy.long, when = RSI< RSI_entry and close < movingaverage_signal and window())+if RSI< RSI_entry and close < movingaverage_signal and window()+ strategy.entry(id="long", direction = strategy.long)//Exit//RSI-strategy.close("long", when = RSI > RSI_exit and window())+if RSI > RSI_exit and window()+ strategy.close("long")plot (movingaverage_signal)Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L4:C191: the argument 'default_qty_type' is specified more than once. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Coinrule-//@version=5+//@version=6strategy(shorttitle='Optimized RSI Strategy',title='Optimized RSI Strategy - Buy The Dips (by Coinrule)', overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_type = strategy.percent_of_equity, default_qty_value = 30, 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 |
| RSI Entry | 35 | int · min 1 | entry long |
| RSI Close | 65 | int · min 1 | close long |
| Movingaverage signal (no label in the script) | 100 | int | entry long plot |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, lengthRSIRSI · line 18
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< RSI_entry and close < movingaverage_signal and window() | On | 24 |
| Close long | RSI > RSI_exit and window() | On | 27 |
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 | −0.2% | +102.5% | 6 | 50% | 0.96 | 10.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.0% | +5.5% | 7 | 86% | 0.99 | 6.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −18.8% | +9.8% | 5 | 0% | 0.00 | 23.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.4% | +8.4% | 6 | 67% | 0.76 | 7.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +22.0% | +16.7% | 8 | 63% | 1.97 | 18.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +2.3% | +21.5% | 5 | 80% | 1.63 | 7.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +7.8% | +148.3% | 6 | 83% | 2.54 | 8.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.7% | +17.1% | 6 | 50% | 3.06 | 3.7% | 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 | 5 | 60% | $26.16 |
| Falling market | 1 | 0% | −$28.38 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.9%
The 95th percentile of the worst drawdown when the same 6 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.7% to 5.9%; the tick is what actually happened, 5.9%. Order luck alone moves it this much.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Jun 2024 63,210.00 | 21 Jul 2024 67,140.00 | 27 | $18.02 |
| long | 5 Aug 2024 58,161.00 | 27 Sep 2024 65,174.00 | 53 | $36.14 |
| long | 25 Feb 2025 91,552.90 | 23 Apr 2025 93,443.00 | 57 | $5.88 |
| long | 5 Nov 2025 101,497.00 | 6 Jan 2026 93,859.70 | 62 | −$24.52 |
| long | 30 Jan 2026 84,650.20 | 18 Apr 2026 77,072.00 | 78 | −$28.38 |
| long | 2 Jun 2026 71,408.90 | 20 Aug 2026 69,334.80 | 79 | −$9.36 |
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 |
|---|---|---|---|---|---|
| Optimized RSI Strategy - Buy The Dips (by Coinrule) this page | — | v4 strategy | −0.2% | 6 | 10.9% |
| 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 8 ms | With a workaround 1,000 bars in 31 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 24) 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/// © Coinrule//@version=4strategy(shorttitle='Optimized RSI Strategy',title='Optimized RSI Strategy - Buy The Dips (by Coinrule)', overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_type = strategy.percent_of_equity, default_qty_value = 30, 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"// RSI inputs and calculationslengthRSI = (14)RSI = rsi(close, lengthRSI)RSI_entry = input(35, title = 'RSI Entry', minval=1)RSI_exit = input(65, title = 'RSI Close', minval=1)//Calculate Moving Averagesmovingaverage_signal = sma(close, input(100))//Entry strategy.entry(id="long", long = true, when = RSI< RSI_entry and close < movingaverage_signal and window())//Exit//RSIstrategy.close("long", when = RSI > RSI_exit and window())plot (movingaverage_signal)