Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

BTC-USD - RSI

A Pine Script v5 strategy built on RSI (close, 14). It has 6 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 8 settings; defaults include Length 14, Buy Level 1 27 and Buy Level 2 18.

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 BTC-USD - RSI repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 24 of 24 trades.
How did BTC-USD - RSI do on BTCUSDT 1D with default settings?
−20.00%
From 26 Jan 2024 to 21 Oct 2026, over 104 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does BTC-USD - RSI 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: 104 before, 0 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does BTC-USD - RSI use a stop loss?
Yes
strategy.exit sets a stop on line 35, 36.
Does BTC-USD - RSI run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • Overbought Zone
  • Overbought Zone
  • Oversold Zone
  • Oversold Zone
  • RSI
  • 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 (8)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctOverbought Zone$4,000$10,126Equity from $5,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. 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
−20.00%
−$1,000.00
Buy and hold
+102.5%
same period
Closed trades
104
56 won · 48 lost
Profitable
53.8%
of closed trades
Profit factor
0.58
gross profit ÷ gross loss
Max drawdown
22.33%
−$1,150.00

One run with the author's default settings, $5,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.

  • 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.

SettingDefaultType and rangeFeeds
LengthRSI period14intvrsi
Buy Level 1Level where 1st buy triggers27intlong1 hline
Buy Level 2Level where 2nd buy triggers18intlong1 long2 hline
Sell Level 1Level where 1st sell triggers68intshort1 hline
Sell Level 2Level where 2nd sell triggers80intshort1 short2 hline
target PipsFixed pip stop loss distance2500intexit Long Exit exit Short Exit
Stop PipsFixed pip stop loss distance5000intexit Long Exit exit Short Exit
Lot SizeTrading Lot size1intentry Long entry Short exit Long Exit exit Short Exit

What it calculates

  • RSIclose, Length (14)vrsi · line 16

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 datalengthLengthsetting · 14first_buy_levelBuy Level 1setting · 27second_buy_levelBuy Level 2setting · 18first_sell_levelSell Level 1setting · 68second_sell_levelSell Level 2setting · 80vrsiRSI→ vrsilong1long1conditionlong2long2conditionshort1short1conditionshort2short2conditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long Exitexit Long Exitstrategy.exitexit:Short Exitexit Short Exitstrategy.exithline:38hlinehlinehline:39hlinehlinehline:40hlinehlinehline:41hlinehlineplot:42RSIplot

Order rules

OrderFires whenBy defaultLine
Open Long long(long1 and strategy.position_size == 0)On25
Open Long long(long2 and strategy.position_size == 0)On27
Open Short short(short1 and strategy.position_size == 0)On30
Open Short short(short2 and strategy.position_size == 0)On32
Exit Long Exit stop and limitevery barOn35
Exit Short Exit stop and limitevery barOn36

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.

24/24trades 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−20.0%+102.5%10454%0.5822.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−11.0%+5.5%7457%0.6614.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−10.0%+9.8%8859%0.7213.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.5%+8.4%4166%0.963.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.0%+16.7%1173%1.331.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.0%+21.5%2100%—0.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.5%+148.3%4663%0.855.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.0%+17.1%1675%1.501.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 market5058%−$325.00
Sideways market4747%−$700.00
Falling market771%$25.00

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

How bad could the drawdown be?

23.9%

The 95th percentile of the worst drawdown when the same 104 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 20.0% to 23.9%; the tick is what actually happened, 22.3%. Order luck alone moves it this much.

0%27%
All 104 trades
SideEntryExitBarsP&L
short22 Feb 2024 51,849.4022 Feb 2024 51,899.400−$50.00
short23 Feb 2024 51,288.4023 Feb 2024 51,338.400−$50.00
short24 Feb 2024 50,744.2024 Feb 2024 50,719.200$25.00
short25 Feb 2024 51,568.2025 Feb 2024 51,543.200$25.00
short26 Feb 2024 51,728.8026 Feb 2024 51,703.800$25.00
short27 Feb 2024 54,476.5027 Feb 2024 54,451.500$25.00
short6 Mar 2024 63,724.006 Mar 2024 63,699.000$25.00
short7 Mar 2024 66,074.007 Mar 2024 66,049.000$25.00
short8 Mar 2024 66,823.208 Mar 2024 66,798.200$25.00
short9 Mar 2024 68,124.209 Mar 2024 68,099.200$25.00
short10 Mar 2024 68,313.3010 Mar 2024 68,288.300$25.00
short11 Mar 2024 68,955.9011 Mar 2024 68,930.900$25.00
short12 Mar 2024 72,078.1012 Mar 2024 72,128.100−$50.00
short13 Mar 2024 71,452.0013 Mar 2024 71,427.000$25.00
short14 Mar 2024 73,072.4014 Mar 2024 73,122.400−$50.00
short15 Mar 2024 71,388.9015 Mar 2024 71,438.900−$50.00
long25 Jun 2024 60,293.3025 Jun 2024 60,318.300$25.00
long6 Aug 2024 54,018.806 Aug 2024 53,968.800−$50.00
short19 Oct 2024 68,428.0019 Oct 2024 68,478.000−$50.00
short20 Oct 2024 68,378.0020 Oct 2024 68,353.000$25.00
short21 Oct 2024 69,032.0021 Oct 2024 69,082.000−$50.00
short30 Oct 2024 72,736.4030 Oct 2024 72,786.400−$50.00
short31 Oct 2024 72,344.8031 Oct 2024 72,394.800−$50.00
short7 Nov 2024 75,572.007 Nov 2024 75,547.000$25.00
short8 Nov 2024 75,857.908 Nov 2024 75,832.900$25.00
short9 Nov 2024 76,509.809 Nov 2024 76,559.800−$50.00
short10 Nov 2024 76,677.5010 Nov 2024 76,652.500$25.00
short11 Nov 2024 80,370.0011 Nov 2024 80,345.000$25.00
short15 Nov 2024 87,325.6015 Nov 2024 87,300.600$25.00
short16 Nov 2024 91,032.1016 Nov 2024 91,082.100−$50.00
short17 Nov 2024 90,588.0017 Nov 2024 90,638.000−$50.00
short18 Nov 2024 89,856.0018 Nov 2024 89,831.000$25.00
short19 Nov 2024 90,464.1019 Nov 2024 90,439.100$25.00
short20 Nov 2024 92,310.8020 Nov 2024 92,285.800$25.00
short21 Nov 2024 94,286.6021 Nov 2024 94,261.600$25.00
short24 Nov 2024 97,672.4024 Nov 2024 97,722.400−$50.00
short25 Nov 2024 97,900.1025 Nov 2024 97,950.100−$50.00
short30 Nov 2024 97,460.0030 Nov 2024 97,435.000$25.00
short9 Dec 2024 101,110.009 Dec 2024 101,160.000−$50.00
short17 Dec 2024 106,059.0017 Dec 2024 106,034.000$25.00
short18 Dec 2024 106,134.0018 Dec 2024 106,184.000−$50.00
long27 Feb 2025 84,250.1027 Feb 2025 84,200.100−$50.00
long28 Feb 2025 84,708.6028 Feb 2025 84,733.600$25.00
long1 Mar 2025 84,349.901 Mar 2025 84,299.900−$50.00
short25 Apr 2025 93,980.5025 Apr 2025 93,955.500$25.00
short26 Apr 2025 94,638.7026 Apr 2025 94,688.700−$50.00
short27 Apr 2025 94,628.0027 Apr 2025 94,678.000−$50.00
short29 Apr 2025 95,011.2029 Apr 2025 95,061.200−$50.00
short2 May 2025 96,489.902 May 2025 96,464.900$25.00
short3 May 2025 96,887.103 May 2025 96,862.100$25.00
short9 May 2025 103,262.009 May 2025 103,237.000$25.00
short10 May 2025 102,972.0010 May 2025 102,947.000$25.00
short11 May 2025 104,810.0011 May 2025 104,860.000−$50.00
short12 May 2025 104,118.0012 May 2025 104,168.000−$50.00
short13 May 2025 102,791.0013 May 2025 102,766.000$25.00
short14 May 2025 104,104.0014 May 2025 104,154.000−$50.00
short15 May 2025 103,508.0015 May 2025 103,558.000−$50.00
short16 May 2025 103,764.0016 May 2025 103,739.000$25.00
short17 May 2025 103,464.0017 May 2025 103,514.000−$50.00
short19 May 2025 106,454.0019 May 2025 106,504.000−$50.00
short20 May 2025 105,574.0020 May 2025 105,549.000$25.00
short21 May 2025 106,850.0021 May 2025 106,825.000$25.00
short22 May 2025 109,644.0022 May 2025 109,619.000$25.00
short23 May 2025 111,696.0023 May 2025 111,746.000−$50.00
short11 Jul 2025 116,010.0011 Jul 2025 115,985.000$25.00
short12 Jul 2025 117,528.0012 Jul 2025 117,503.000$25.00
short13 Jul 2025 117,420.0013 Jul 2025 117,395.000$25.00
short14 Jul 2025 119,087.0014 Jul 2025 119,062.000$25.00
short15 Jul 2025 119,841.0015 Jul 2025 119,891.000−$50.00
short17 Jul 2025 118,630.0017 Jul 2025 118,605.000$25.00
short18 Jul 2025 119,178.0018 Jul 2025 119,228.000−$50.00
short23 Jul 2025 119,954.0023 Jul 2025 120,004.000−$50.00
short14 Aug 2025 123,306.0014 Aug 2025 123,356.000−$50.00
short4 Oct 2025 122,232.004 Oct 2025 122,282.000−$50.00
short5 Oct 2025 122,391.005 Oct 2025 122,366.000$25.00
short6 Oct 2025 123,482.006 Oct 2025 123,457.000$25.00
short7 Oct 2025 124,659.007 Oct 2025 124,709.000−$50.00
long21 Nov 2025 86,637.2021 Nov 2025 86,662.200$25.00
long22 Nov 2025 85,129.4022 Nov 2025 85,154.400$25.00
long23 Nov 2025 84,739.8023 Nov 2025 84,689.800−$50.00
short15 Jan 2026 96,951.8015 Jan 2026 97,001.800−$50.00
long1 Feb 2026 78,741.101 Feb 2026 78,766.100$25.00
long2 Feb 2026 76,968.202 Feb 2026 76,918.200−$50.00
long4 Feb 2026 75,770.204 Feb 2026 75,795.200$25.00
long5 Feb 2026 73,165.805 Feb 2026 73,190.800$25.00
short7 May 2026 81,447.007 May 2026 81,497.000−$50.00
short11 May 2026 82,210.1011 May 2026 82,260.100−$50.00
long3 Jun 2026 66,760.803 Jun 2026 66,785.800$25.00
long4 Jun 2026 64,142.804 Jun 2026 64,167.800$25.00
long5 Jun 2026 63,886.005 Jun 2026 63,911.000$25.00
long8 Jun 2026 63,332.008 Jun 2026 63,357.000$25.00
long9 Jun 2026 63,086.009 Jun 2026 63,111.000$25.00
long10 Jun 2026 61,730.0010 Jun 2026 61,680.000−$50.00
long11 Jun 2026 61,511.0011 Jun 2026 61,536.000$25.00
short20 Aug 2026 69,334.8020 Aug 2026 69,309.800$25.00
short26 Aug 2026 78,539.1026 Aug 2026 78,589.100−$50.00
short29 Aug 2026 77,845.9029 Aug 2026 77,820.900$25.00
short30 Aug 2026 78,230.0030 Aug 2026 78,280.000−$50.00
short31 Aug 2026 77,682.0031 Aug 2026 77,657.000$25.00
short1 Sep 2026 78,581.301 Sep 2026 78,631.300−$50.00
short4 Sep 2026 81,270.404 Sep 2026 81,320.400−$50.00
short22 Sep 2026 86,620.0022 Sep 2026 86,670.000−$50.00
short23 Sep 2026 86,208.6023 Sep 2026 86,258.600−$50.00
short5 Oct 2026 86,530.005 Oct 2026 86,580.000−$50.00

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
BTC-USD - RSI this page—v5 strategy−20.0%10422.3%
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%

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.

  • 8 settings use the untyped input() (line 7, 8, 9, 10, 11, 12, 13, 14). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
⋯// User input-length = input(title = "Length", defval=14, tooltip="RSI period")+length = input.int(title = "Length", defval=14, tooltip="RSI period")-first_buy_level = input(title = "Buy Level 1", defval=27, tooltip="Level where 1st buy triggers")+first_buy_level = input.int(title = "Buy Level 1", defval=27, tooltip="Level where 1st buy triggers")-second_buy_level = input(title = "Buy Level 2", defval=18, tooltip="Level where 2nd buy triggers")+second_buy_level = input.int(title = "Buy Level 2", defval=18, tooltip="Level where 2nd buy triggers")-first_sell_level = input(title = "Sell Level 1", defval=68, tooltip="Level where 1st sell triggers")+first_sell_level = input.int(title = "Sell Level 1", defval=68, tooltip="Level where 1st sell triggers")-second_sell_level = input(title = "Sell Level 2", defval=80, tooltip="Level where 2nd sell triggers")+second_sell_level = input.int(title = "Sell Level 2", defval=80, tooltip="Level where 2nd sell triggers")-takeProfit= input(title="target Pips", defval=2500, tooltip="Fixed pip stop loss distance")+takeProfit= input.int(title="target Pips", defval=2500, tooltip="Fixed pip stop loss distance")-stopLoss = input(title="Stop Pips", defval=5000, tooltip="Fixed pip stop loss distance")+stopLoss = input.int(title="Stop Pips", defval=5000, tooltip="Fixed pip stop loss distance")-lot = input(title = "Lot Size", defval = 1, tooltip="Trading Lot size")+lot = input.int(title = "Lot Size", defval = 1, tooltip="Trading Lot size")// Get RSI⋯

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

⋯// Ramy's Algorithm-//@version=5+//@version=6strategy("BTC/USD - RSI", overlay=false, initial_capital = 5000)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msWith a workaround 1,000 bars in 32 msNot measured
PineTSNot testedNot testedNot measured

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/// © Rawadabdo// Ramy's Algorithm//@version=5strategy("BTC/USD - RSI", overlay=false, initial_capital = 5000)// User inputlength = input(title = "Length", defval=14, tooltip="RSI period")first_buy_level = input(title = "Buy Level 1", defval=27, tooltip="Level where 1st buy triggers")second_buy_level = input(title = "Buy Level 2", defval=18, tooltip="Level where 2nd buy triggers")first_sell_level = input(title = "Sell Level 1", defval=68, tooltip="Level where 1st sell triggers")second_sell_level = input(title = "Sell Level 2", defval=80, tooltip="Level where 2nd sell triggers")takeProfit= input(title="target Pips", defval=2500, tooltip="Fixed pip stop loss distance")stopLoss = input(title="Stop Pips", defval=5000, tooltip="Fixed pip stop loss distance")lot = input(title = "Lot Size", defval = 1, tooltip="Trading Lot size")// Get RSIvrsi = ta.rsi(close, length)// Entry Conditionslong1 = (vrsi <= first_buy_level and vrsi>second_buy_level)long2 = (vrsi <= second_buy_level)short1= (vrsi >= first_sell_level and vrsi<second_sell_level)short2= (vrsi >= second_sell_level)// Entry Orders// Buy Ordersif (long1 and strategy.position_size == 0)    strategy.entry("Long", strategy.long, qty=lot, comment="Buy")    if (long2 and  strategy.position_size == 0)        strategy.entry("Long", strategy.long, qty=lot, comment="Buy")// Short Ordersif (short1 and strategy.position_size == 0)    strategy.entry("Short", strategy.short,qty=lot, comment="Sell")    if (short2 and strategy.position_size == 0)        strategy.entry("Short", strategy.short,qty=lot, comment="Sell")    // Exit our trade if our stop loss or take profit is hitstrategy.exit(id="Long Exit", from_entry="Long",qty = lot, profit=takeProfit, loss=stopLoss)strategy.exit(id="Short Exit", from_entry="Short", qty = lot, profit=takeProfit, loss=stopLoss)// plot data to the charthline(first_sell_level, "Overbought Zone", color=color.red, linestyle=hline.style_dashed, linewidth = 2)hline(second_sell_level, "Overbought Zone", color=color.green, linestyle=hline.style_dashed, linewidth = 2)hline(first_buy_level, "Oversold Zone", color=color.red, linestyle=hline.style_dashed, linewidth = 2)hline(second_buy_level, "Oversold Zone", color=color.green, linestyle=hline.style_dashed, linewidth = 2)plot (vrsi, title = "RSI", color = color.blue, linewidth=2)