Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

dirt cheap yet elegant RSI Strategy

A Pine Script v4 strategy built on RSI (close, 14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 4 settings; defaults include RSI length 14, Overbought level 80 and Oversold level 20.

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 dirt cheap yet elegant RSI Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did dirt cheap yet elegant RSI Strategy do on BTCUSDT 1D with default settings?
−11.43%
From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can dirt cheap yet elegant RSI Strategy 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 dirt cheap yet elegant RSI Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does dirt cheap yet elegant RSI Strategy run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 18 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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 (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct80205RSI$88,566$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 20, 22) so the engine trades the way the script says.
Net profit
−11.43%
−$11,432.40
Buy and hold
+102.5%
same period
Closed trades
8
4 won · 4 lost
Profitable
50.0%
of closed trades
Profit factor
0.49
gross profit ÷ gross loss
Max drawdown
20.54%
−$20,542.60

One run with the author's default settings, $100,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 stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

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

  • Note

    Uses an argument v6 removed

    when = on line 20, 21, 22, 23. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 20

    long = on line 20, 22. 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, barssince → ta.barssince, crossunder → ta.crossunder, crossover → ta.crossover.
  • 4 strategy calls use the when = argument (line 20, 21, 22, 23). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 1: //@version=4 → //@version=5
  • Line 14: rsi → ta.rsi
  • Line 17: barssince → ta.barssince
  • Line 17: crossunder → ta.crossunder
  • Line 19: barssince → ta.barssince
  • Line 19: crossover → ta.crossover
  • Line 20: long = true → direction = strategy.long
  • Line 22: long = false → direction = strategy.short
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯//RSI-rsi = rsi(close, length)+rsi = ta.rsi(close, length)//Strategybuy = rsi < os-sell = rsi > os or barssince(crossunder(rsi,os)) > stopLength+sell = rsi > os or ta.barssince(ta.crossunder(rsi,os)) > stopLengthshort = rsi > ob-cover = rsi < ob or barssince(crossover(rsi,ob)) > stopLength+cover = rsi < ob or ta.barssince(ta.crossover(rsi,ob)) > stopLength-strategy.entry(id="enter long", long=true, when=buy)+strategy.entry(id="enter long", direction = strategy.long, when=buy)strategy.close(id="enter long", comment="exit long", when=sell)-strategy.entry(id="enter short", long=false, when=short)+strategy.entry(id="enter short", direction = strategy.short, when=short)strategy.close(id="enter short", comment="exit short", when=cover)

Clean v5

VerifiedDownload the v5 script

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

  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 20: when = buy → if block
  • Line 21: when = sell → if block
  • Line 22: when = short → if block
  • Line 23: when = cover → if block
⋯//Inputs-length = input(14, title="RSI length")+length = input.int(14, title="RSI length")-ob = input(80, title="Overbought level")+ob = input.int(80, title="Overbought level")-os = input(20, title="Oversold level")+os = input.int(20, title="Oversold level")-stopLength = input(5, title="Time Stop length to exit")+stopLength = input.int(5, title="Time Stop length to exit")//RSI⋯cover = rsi < ob or ta.barssince(ta.crossover(rsi,ob)) > stopLength-strategy.entry(id="enter long", direction = strategy.long, when=buy)+if buy+    strategy.entry(id="enter long", direction = strategy.long)-strategy.close(id="enter long", comment="exit long", when=sell)+if sell+    strategy.close(id="enter long", comment="exit long")-strategy.entry(id="enter short", direction = strategy.short, when=short)+if short+    strategy.entry(id="enter short", direction = strategy.short)-strategy.close(id="enter short", comment="exit short", when=cover)+if cover+    strategy.close(id="enter short", comment="exit short")

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

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
RSI length14intrsi
Overbought level80intshort cover
Oversold level20intbuy sell
Time Stop length to exit5intsell cover

What it calculates

  • RSI (rsi, ta.rsi in v5)close, RSI length (14)rsi · line 14

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 datalengthRSI lengthsetting · 14osOversold levelsetting · 20stopLengthTime Stop length to exitsetting · 5obOverbought levelsetting · 80rsiRSI→ rsibuybuyconditionsellsellconditionshortshortconditioncovercoverconditionentry:enter longOpen enter longstrategy.entryclose:enter longClose enter longstrategy.closeentry:enter shortOpen enter shortstrategy.entryclose:enter shortClose enter shortstrategy.close

Order rules

OrderFires whenBy defaultLine
Open enter long longbuyrsi < osOn20
Close enter longsellrsi > os or barssince(crossunder(rsi,os)) > stopLengthOn21
Open enter short shortshortrsi > obOn22
Close enter shortcoverrsi < ob or barssince(crossover(rsi,ob)) > stopLengthOn23

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.

4/4trades 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−11.4%+102.5%850%0.4920.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−8.1%+5.5%1233%0.2811.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.3%+9.8%1323%0.221.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.3%+8.4%1354%0.470.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%650%2.600.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%1338%0.470.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%1267%1.780.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%560%0.180.1%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 market367%−$9,241.23
Sideways market425%−$9,861.58
Falling market1100%$7,670.39

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

How bad could the drawdown be?

21.6%

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

0%25%
All 8 trades
SideEntryExitBarsP&L
short10 Feb 2024 47,132.8022 Feb 2024 51,849.4012−$4,716.60
short28 Feb 2024 57,037.305 Mar 2024 68,245.706−$11,208.40
short12 Nov 2024 88,648.0015 Nov 2024 87,325.603$1,322.41
short22 Nov 2024 98,317.1024 Nov 2024 97,672.402$644.72
long6 Feb 2026 62,909.907 Feb 2026 70,580.301$7,670.39
long4 Jun 2026 64,142.808 Jun 2026 63,332.004−$810.74
short21 Aug 2026 73,027.0026 Aug 2026 78,539.105−$5,512.11
short27 Aug 2026 79,023.8029 Aug 2026 77,845.902$1,177.87

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
dirt cheap yet elegant RSI Strategy this page—v4 strategy−11.4%820.5%
Triple RSI strategy by Trade_by_DBrsiv5 strategy+3.2%23.3%
Hobbiecode - RSI + Close previous day by hobbiecodersiv5 strategy+1.2%634.2%
RSI Classic Strategy (by Coinrule) by Coinrulersiv4 strategy+7.5%67.2%
RSITrendStrategy by email_analystsrsiv4 strategy+69.2%2238.6%
Cheat Code- Example 1; Short-Term; Follow the Trend by CheatCode1rsiv5 strategy−1.0%25.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msWith a workaround 1,000 bars in 18 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 20, 22) 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.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// dirt cheap yet elegant RSI Strategy// by SparkyFlary//For Educational Purposes//Results can differ on different markets and can fail at any time. Profit is not guaranteed.strategy(title="dirt cheap yet elegant RSI Strategy", shorttitle="RSI Strategy", overlay=true)//Inputslength = input(14, title="RSI length")ob = input(80, title="Overbought level")os = input(20, title="Oversold level")stopLength = input(5, title="Time Stop length to exit")//RSIrsi = rsi(close, length)//Strategybuy = rsi < ossell = rsi > os or barssince(crossunder(rsi,os)) > stopLengthshort = rsi > obcover = rsi < ob or barssince(crossover(rsi,ob)) > stopLengthstrategy.entry(id="enter long", long=true, when=buy)strategy.close(id="enter long", comment="exit long", when=sell)strategy.entry(id="enter short", long=false, when=short)strategy.close(id="enter short", comment="exit short", when=cover)