Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Optimised RSI strategy for Reversals (by Coinrule)

A Pine Script v4 strategy built on SMA (close, 9) and RSI (close, 14). It has 2 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 no commission. 11 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 Optimised RSI strategy for Reversals (by Coinrule) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
How did Optimised RSI strategy for Reversals (by Coinrule) do on BTCUSDT 1D with default settings?
+1.92%
From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Optimised RSI strategy for Reversals (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 Optimised RSI strategy for Reversals (by Coinrule) use a stop loss?
Yes
strategy.exit sets a stop on line 32.
Does Optimised RSI strategy for Reversals (by Coinrule) run in Zeal Terminal?
Yes
It compiles in 10 ms and runs 1,000 bars in 37 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 (11)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,019$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 23) 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.
Net profit
+1.92%
$19.17
Buy and hold
+102.5%
same period
Closed trades
7
3 won · 4 lost
Profitable
42.9%
of closed trades
Profit factor
1.27
gross profit ÷ gross loss
Max drawdown
4.19%
−$43.80

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

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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 23. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 33

    transp = on line 33. v5 folds the transparency into the colour with color.new(c, transp).

  • 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 sma → ta.sma, rsi → ta.rsi.
  • 1 strategy call uses the when = argument (line 23). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 7 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()
8 more edits
  • Line 11: input(type = input.integer) → input.int()
  • Line 12: input(type = input.bool) → input.bool()
  • Line 18: sma → ta.sma
  • Line 21: rsi → ta.rsi
  • Line 23: long = true → direction = strategy.long
  • Line 25: input(type = input.float) → input.float()
  • Line 27: input(type = input.float) → input.float()
  • Line 33: transp = 90 → color.new(showDate and window() ? color.gray : na, 90)
⋯// © Coinrule-//@version=4+//@version=5strategy(shorttitle='MARSI',title='Moving Average', overlay=true, initial_capital=1000,  default_qty_type = strategy.percent_of_equity, default_qty_value = 100)//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⋯inshort=input(9, title='MA short period')-MAshort= sma(close, inshort)+MAshort= ta.sma(close, inshort)// RSI inputs and calculationslengthRSI = input(14, title = 'RSI period', minval=1)-RSI = rsi(close, lengthRSI)+RSI = ta.rsi(close, lengthRSI)//Entry -strategy.entry(id="long", long = true, when = MAshort<close and RSI<40 and window())+strategy.entry(id="long", direction = strategy.long, when = MAshort<close and RSI<40 and window())//Exit-longLossPerc = input(title="Long Stop Loss (%)",-     type=input.float, minval=0.0, step=0.1, defval=1.5) * 0.01+longLossPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=1.5) * 0.01-longTakePerc = input(title="Long Take Profit (%)",-     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01+longTakePerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=3) * 0.01longSL  = strategy.position_avg_price * (1 - longLossPerc)⋯    strategy.exit(id="TP/SL", stop=longSL, limit=longTP)-bgcolor(color = showDate and window() ? color.gray : na, transp = 90)  +bgcolor(color = color.new(showDate and window() ? color.gray : na, 90))  plot(MAshort, color=color.purple, linewidth=4)

Clean v5

VerifiedDownload the v5 script

Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 17: input() → input.int()
  • Line 20: input() → input.int()
  • Line 23: when = MAshort<close and RSI<40 and window() → if block
⋯//MA inputs and calculations-inshort=input(9, title='MA short period')+inshort=input.int(9, title='MA short period')MAshort= ta.sma(close, inshort)// RSI inputs and calculations-lengthRSI = input(14, title = 'RSI period', minval=1)+lengthRSI = input.int(14, title = 'RSI period', minval=1)RSI = ta.rsi(close, lengthRSI)//Entry -strategy.entry(id="long", direction = strategy.long, when = MAshort<close and RSI<40 and window())+if MAshort<close and RSI<40 and window()+    strategy.entry(id="long", direction = strategy.long)//Exit⋯

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: 7 before, 7 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.

⋯// © Coinrule-//@version=5+//@version=6strategy(shorttitle='MARSI',title='Moving Average', overlay=true, initial_capital=1000,  default_qty_type = strategy.percent_of_equity, default_qty_value = 100)⋯

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 Rangetrueboolbgcolor
MA short period9intMAshort
RSI period14int · min 1RSI
Long Stop Loss (%)1.5float · min 0.0 · step 0.1longSL
Long Take Profit (%)3float · min 0.0 · step 0.1longTP

What it calculates

  • SMA (sma, ta.sma in v5)close, MA short period (9)MAshort · line 18
  • RSI (rsi, ta.rsi in v5)close, RSI period (14)RSI · 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.

closecloseprice datainshortMA short periodsetting · 9lengthRSIRSI periodsetting · 14fromYearFrom Yearsetting · 2020fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1thruYearThru Yearsetting · 2112thruMonthThru Monthsetting · 1thruDayThru Daysetting · 1longLossPercLong Stop Loss (%)setting · 1.5longTakePercLong Take Profit (%)setting · 3MAshortSMA→ MAshortRSIRSI→ RSIstartstartvaluefinishfinishvaluelongSLlongSLvaluelongTPlongTPvalueentry:longOpen longstrategy.entryexit:TP/SLexit TP/SLstrategy.exitbgcolor:33bgcolorbgcolorplot:34plotplot

Order rules

OrderFires whenBy defaultLine
Open long longMAshort<close and RSI<40 and window()On23
Exit TP/SL stop and limit(strategy.position_size > 0 and window())On32

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.

5/5trades 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+1.9%+102.5%743%1.274.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.6%+5.5%425%0.654.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+8.9%+9.8%1145%1.907.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%633%0.984.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.6%+16.7%743%1.188.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+11.5%+21.5%863%3.383.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−4.3%+148.3%520%0.3910.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+7.6%+17.1%475%5.661.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 barsTradesWonP&L
Rising market0—$0.00
Sideways market367%$35.30
Falling market425%−$16.13

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

6.7%

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.0% to 6.7%; the tick is what actually happened, 3.0%. Order luck alone moves it this much.

0%8%
All 7 trades
SideEntryExitBarsP&L
long13 Jul 2024 57,889.1014 Jul 2024 59,625.801$30.00
long27 Nov 2025 90,484.001 Dec 2025 89,126.704−$15.45
long14 Feb 2026 68,854.0015 Feb 2026 70,919.601$30.44
long16 Feb 2026 68,832.6017 Feb 2026 67,800.101−$15.67
long21 Feb 2026 68,020.0023 Feb 2026 66,999.702−$15.44
long12 Jun 2026 63,626.0014 Jun 2026 65,534.802$30.42
long18 Jun 2026 64,509.4019 Jun 2026 62,958.001−$25.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.

ScriptSharesTypeNetTradesMax drawdown
Optimised RSI strategy for Reversals (by Coinrule) this page—v4 strategy+1.9%74.2%
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%
RSI SMA Crossover Strategy by reeesrsi smav5 strategy+39.8%4230.8%
Short In Downtrend Below MA100 (Coinrule) by Coinrulesma rsiv4 strategy−34.5%9945.4%
Simple RSI and SMA Long and Short (by Coinrule) by Coinrulersi smav5 strategy−3.0%217.7%
Maximized Moving Average Crossing (by Coinrule) by Coinrulesma rsiv4 strategy−6.6%913.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 10 msWith a workaround 1,000 bars in 37 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 23) 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. 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='MARSI',title='Moving Average', overlay=true, initial_capital=1000,  default_qty_type = strategy.percent_of_equity, default_qty_value = 100)//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"//MA inputs and calculationsinshort=input(9, title='MA short period')MAshort= sma(close, inshort)// RSI inputs and calculationslengthRSI = input(14, title = 'RSI period', minval=1)RSI = rsi(close, lengthRSI)//Entry strategy.entry(id="long", long = true, when = MAshort<close and RSI<40 and window())//ExitlongLossPerc = input(title="Long Stop Loss (%)",     type=input.float, minval=0.0, step=0.1, defval=1.5) * 0.01longTakePerc = input(title="Long Take Profit (%)",     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01longSL  = strategy.position_avg_price * (1 - longLossPerc)longTP  = strategy.position_avg_price * (1 + longTakePerc)if (strategy.position_size > 0 and window())    strategy.exit(id="TP/SL", stop=longSL, limit=longTP)bgcolor(color = showDate and window() ? color.gray : na, transp = 90)  plot(MAshort, color=color.purple, linewidth=4)