Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$998$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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

Verified

Same 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⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
From Month1int (written input.integer) · min 1 · max 12start
From Day1int (written input.integer) · min 1 · max 31start
From Year2020int (written input.integer) · min 1970start
Thru Month1int (written input.integer) · min 1 · max 12finish
Thru Day1int (written input.integer) · min 1 · max 31finish
Thru Year2112int (written input.integer) · min 1970finish
Show Date Rangetrueboolunused
RSI Entry35int · min 1entry long
RSI Close65int · min 1close long
Movingaverage signal (no label in the script)100intentry long plot

What it calculates

  • RSI (rsi, ta.rsi in 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.

closecloseprice datafromYearFrom Yearsetting · 2020fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1thruYearThru Yearsetting · 2112thruMonthThru Monthsetting · 1thruDayThru Daysetting · 1RSI_entryRSI Entrysetting · 35movingaverage_signalMovingaverage signalsetting · 100RSI_exitRSI Closesetting · 65RSIRSI→ RSIstartstartvaluefinishfinishvalueentry:longOpen longstrategy.entryclose:longClose longstrategy.closeplot:28plotplot

Order rules

OrderFires whenBy defaultLine
Open long longRSI< RSI_entry and close < movingaverage_signal and window()On24
Close longRSI > RSI_exit and window()On27

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.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−0.2%+102.5%650%0.9610.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.0%+5.5%786%0.996.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−18.8%+9.8%50%0.0023.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.4%+8.4%667%0.767.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+22.0%+16.7%863%1.9718.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.3%+21.5%580%1.637.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+7.8%+148.3%683%2.548.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.7%+17.1%650%3.063.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 barsTradesWonP&L
Rising market0—$0.00
Sideways market560%$26.16
Falling market10%−$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.

0%7%
All 6 trades
SideEntryExitBarsP&L
long24 Jun 2024 63,210.0021 Jul 2024 67,140.0027$18.02
long5 Aug 2024 58,161.0027 Sep 2024 65,174.0053$36.14
long25 Feb 2025 91,552.9023 Apr 2025 93,443.0057$5.88
long5 Nov 2025 101,497.006 Jan 2026 93,859.7062−$24.52
long30 Jan 2026 84,650.2018 Apr 2026 77,072.0078−$28.38
long2 Jun 2026 71,408.9020 Aug 2026 69,334.8079−$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.

ScriptSharesTypeNetTradesMax drawdown
Optimized RSI Strategy - Buy The Dips (by Coinrule) this page—v4 strategy−0.2%610.9%
Triple RSI strategy by Trade_by_DBrsiv5 strategy+3.2%23.3%
Hobbiecode - RSI + Close previous day by hobbiecodersiv5 strategy+1.2%634.2%
dirt cheap yet elegant RSI Strategy by SparkyFlaryrsiv4 strategy−11.4%820.5%
RSI Classic Strategy (by Coinrule) by Coinrulersiv4 strategy+7.5%67.2%
RSITrendStrategy by email_analystsrsiv4 strategy+69.2%2238.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 8 msWith a workaround 1,000 bars in 31 msNot measured
PineTSNo 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)