Pine Script v4 · Strategy
Crypto ZigZag RSI strategy 15min
A Pine Script v4 strategy built on RSI (p, 5), Crossover (vrsi, 25) and Crossunder (vrsi, 75). 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. 6 settings; defaults include RSI Length 5, Over Sold 25 and Over Bought 75.
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 Crypto ZigZag RSI strategy 15min repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did Crypto ZigZag RSI strategy 15min do on BTCUSDT 1D with default settings?
- +7.19%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Crypto ZigZag RSI strategy 15min 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 Crypto ZigZag RSI strategy 15min use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Crypto ZigZag RSI strategy 15min run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 25 ms, in the browser.
BTCUSDT · 1D · default settings
- Crossover
- Crossunder
- Crossunder
- Crossover
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +7.19%
- $7,191.83
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 1 won · 2 lost
- Profitable
- 33.3%
- of closed trades
- Profit factor
- 1.27
- gross profit ÷ gross loss
- Max drawdown
- 23.88%
- −$31,876.10
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.
-
Likely bug
crossover(trend, 0) ignores the settings line 54
Line 54 hard-codes 0 where line 12 uses “Over Sold”. Changing those settings moves one band but not this one.
crossover(trend,0)crossover(trend, overSold) -
Likely bug
crossunder(trend, 0) ignores the settings line 53
Line 53 hard-codes 0 where line 13 uses “Over Bought”. Changing those settings moves one band but not this one.
crossunder(trend,0)crossunder(trend, overBought) -
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
4 settings have no label
In the settings dialog overSold (line 6), overBought (line 7), longa (line 55), shorta (line 56) show 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 58, 59, 61, 62. The upgraded version below moves each call inside an if block.
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, crossover → ta.crossover, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 58, 59, 61, 62). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 9: rsi → ta.rsi
- Line 12: crossover → ta.crossover
- Line 13: crossunder → ta.crossunder
- Line 21: input(type = input.float) → input.float()
- Line 53: crossunder → ta.crossunder
3 more edits
- Line 54: crossover → ta.crossover
- Line 58: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 61: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © SoftKill21-//@version=4+//@version=5strategy("Crypto ZigZag RSI strategy 15min",overlay=true)⋯p =close-vrsi = rsi(p, length)+vrsi = ta.rsi(p, length)var bool long = navar bool short = na-long :=crossover(vrsi,overSold) +long :=ta.crossover(vrsi,overSold) -short := crossunder(vrsi,overBought)+short := ta.crossunder(vrsi,overBought)var float last_open_long = na⋯//-ZZPercent = input(1, title="Minimum % Change", type=input.float)+ZZPercent = input.float(1, title="Minimum % Change")r1Level=entry_value⋯ HH-shortc=crossunder(trend,0)+shortc=ta.crossunder(trend,0)-longc=crossover(trend,0)+longc=ta.crossover(trend,0)longa =input(true)⋯if(longa)- strategy.entry("long",1,when=longc)+ strategy.entry("long",strategy.long,when=longc) strategy.close("long",when=shortc)if(shorta)- strategy.entry("short",0,when=shortc)+ strategy.entry("short",strategy.short,when=shortc) strategy.close("long",when=longc)Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 55: input() → input.bool()
- Line 56: input() → input.bool()
- Line 58: when = longc → if block
3 more edits
- Line 59: when = shortc → if block
- Line 61: when = shortc → if block
- Line 62: when = longc → if block
⋯strategy("Crypto ZigZag RSI strategy 15min",overlay=true)-length =input(5, title="RSI Length")+length =input.int(5, title="RSI Length")-overSold = input(25)+overSold = input.int(25)-overBought= input(75)+overBought= input.int(75)p =close⋯longc=ta.crossover(trend,0)-longa =input(true)+longa =input.bool(true)-shorta=input(false)+shorta=input.bool(false)if(longa)- strategy.entry("long",strategy.long,when=longc)+ if longc+ strategy.entry("long",strategy.long)- strategy.close("long",when=shortc)+ if shortc+ strategy.close("long")if(shorta)- strategy.entry("short",strategy.short,when=shortc)+ if shortc+ strategy.entry("short",strategy.short)- strategy.close("long",when=longc)+ if longc+ strategy.close("long")Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L10:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © SoftKill21-//@version=5+//@version=6strategy("Crypto ZigZag RSI strategy 15min",overlay=true)⋯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 | 5 | int | vrsi |
| Over Sold (no label in the script) | 25 | int | long |
| Over Bought (no label in the script) | 75 | int | short |
| Minimum % Change | 1 | float | Pi |
| Longa (no label in the script) | true | bool | entry long close long line 57 |
| Shorta (no label in the script) | false | bool | entry short close long line 60 |
What it calculates
- RSI (
rsi,ta.rsiin v5)p, RSI Length (5)vrsi · line 9 - Crossover (
crossover,ta.crossoverin v5)vrsi, Over Sold (25)long · line 12 - Crossunder (
crossunder,ta.crossunderin v5)vrsi, Over Bought (75)short · line 13 - Crossunder (
crossunder,ta.crossunderin v5)trend, 0shortc · line 53 - Crossover (
crossover,ta.crossoverin v5)trend, 0longc · line 54
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 long long | longc | On | 58 |
| Close long | shortc | On | 59 |
| Open short short | shortc | On | 61 |
| Close long | longc | On | 62 |
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 | +7.2% | +102.5% | 3 | 33% | 1.27 | 23.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.3% | +5.5% | 5 | 20% | 0.59 | 3.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.8% | +9.8% | 3 | 67% | 5.34 | 0.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.6% | +8.4% | 4 | 50% | 6.68 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 5 | 60% | 0.51 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 4 | 50% | 1.32 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.1% | +148.3% | 3 | 67% | 1.44 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 1 | 0% | 0.00 | 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 | 2 | 0% | −$26,312.30 |
| Sideways market | 1 | 100% | $33,504.10 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
19.7%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 11.1% to 19.7%; the tick is what actually happened, 19.7%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 4 Oct 2024 60,752.70 | 30 Apr 2025 94,256.80 | 208 | $33,504.10 |
| long | 7 Jun 2025 104,288.00 | 8 Jan 2026 91,364.20 | 215 | −$12,924.30 |
| long | 24 May 2026 76,752.00 | 8 Jul 2026 63,364.00 | 45 | −$13,388.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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Crypto ZigZag RSI strategy 15min this page | — | v4 strategy | +7.2% | 3 | 23.9% |
| 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% |
| dirt cheap yet elegant RSI Strategy by SparkyFlary | rsi | v4 strategy | −11.4% | 8 | 20.5% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 ms | With a workaround 1,000 bars in 25 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 58, 61) 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/// © SoftKill21//@version=4strategy("Crypto ZigZag RSI strategy 15min",overlay=true)length =input(5, title="RSI Length")overSold = input(25)overBought= input(75)p =closevrsi = rsi(p, length)var bool long = navar bool short = nalong :=crossover(vrsi,overSold) short := crossunder(vrsi,overBought)var float last_open_long = navar float last_open_short = nalast_open_long := long ? close : nz(last_open_long[1])last_open_short := short ? close : nz(last_open_short[1])entry_value =last_open_longentry_value1=last_open_short//ZZPercent = input(1, title="Minimum % Change", type=input.float)r1Level=entry_values1Level=entry_value1trend = 0trend := na(trend[1]) ? 1 : trend[1]LL = 0.0LL := na(LL[1]) ? s1Level : LL[1]HH = 0.0HH := na(HH[1]) ?r1Level : HH[1]Pi = ZZPercent * 0.01zigzag = float(na)if trend > 0 if r1Level >= HH HH := r1Level HH else if s1Level < HH * (1 - Pi) zigzag :=r1Level[1] trend := -1 LL := s1Level LLelse if s1Level <= LL LL := s1Level LL else if r1Level > LL * (1 + Pi) zigzag := s1Level[1] trend := 1 HH := s1Level HHshortc=crossunder(trend,0)longc=crossover(trend,0)longa =input(true)shorta=input(false)if(longa) strategy.entry("long",1,when=longc) strategy.close("long",when=shortc)if(shorta) strategy.entry("short",0,when=shortc) strategy.close("long",when=longc)