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
- 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
VerifiedSame 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)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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| RSI length | 14 | int | rsi |
| Overbought level | 80 | int | short cover |
| Oversold level | 20 | int | buy sell |
| Time Stop length to exit | 5 | int | sell cover |
What it calculates
- RSI (
rsi,ta.rsiin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open enter long long | buyrsi < os | On | 20 |
| Close enter long | sellrsi > os or barssince(crossunder(rsi,os)) > stopLength | On | 21 |
| Open enter short short | shortrsi > ob | On | 22 |
| Close enter short | coverrsi < ob or barssince(crossover(rsi,ob)) > stopLength | On | 23 |
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 | −11.4% | +102.5% | 8 | 50% | 0.49 | 20.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −8.1% | +5.5% | 12 | 33% | 0.28 | 11.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.3% | +9.8% | 13 | 23% | 0.22 | 1.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.3% | +8.4% | 13 | 54% | 0.47 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 6 | 50% | 2.60 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 13 | 38% | 0.47 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.1% | +148.3% | 12 | 67% | 1.78 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 5 | 60% | 0.18 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 67% | −$9,241.23 |
| Sideways market | 4 | 25% | −$9,861.58 |
| Falling market | 1 | 100% | $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.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 10 Feb 2024 47,132.80 | 22 Feb 2024 51,849.40 | 12 | −$4,716.60 |
| short | 28 Feb 2024 57,037.30 | 5 Mar 2024 68,245.70 | 6 | −$11,208.40 |
| short | 12 Nov 2024 88,648.00 | 15 Nov 2024 87,325.60 | 3 | $1,322.41 |
| short | 22 Nov 2024 98,317.10 | 24 Nov 2024 97,672.40 | 2 | $644.72 |
| long | 6 Feb 2026 62,909.90 | 7 Feb 2026 70,580.30 | 1 | $7,670.39 |
| long | 4 Jun 2026 64,142.80 | 8 Jun 2026 63,332.00 | 4 | −$810.74 |
| short | 21 Aug 2026 73,027.00 | 26 Aug 2026 78,539.10 | 5 | −$5,512.11 |
| short | 27 Aug 2026 79,023.80 | 29 Aug 2026 77,845.90 | 2 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| dirt cheap yet elegant RSI Strategy this page | — | v4 strategy | −11.4% | 8 | 20.5% |
| 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% |
| 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% |
| Cheat Code- Example 1; Short-Term; Follow the Trend by CheatCode1 | rsi | v5 strategy | −1.0% | 2 | 5.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | With a workaround 1,000 bars in 18 ms | Not measured |
| PineTS | No 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)