Pine Script v4 · Strategy
Crypto RSI with RVI Strategy
A Pine Script v4 strategy built on Stdev (xPrice, 100). It has 4 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 0.03% commission. 8 settings; defaults include Period 100, Buy Zone 49 and Sell Zone 50.
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 RSI with RVI Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Crypto RSI with RVI Strategy do on BTCUSDT 1D with default settings?
- +3.99%
- From 26 Jan 2024 to 21 Oct 2026, over 2 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Crypto RSI with RVI 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 Crypto RSI with RVI Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 75, 76.
- Does Crypto RSI with RVI Strategy run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 48 ms, in the browser.
BTCUSDT · 1D · default settings
- Stdev
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +3.99%
- $39.91
- Buy and hold
- +102.5%
- same period
- Closed trades
- 2
- 1 won · 1 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 1.29
- gross profit ÷ gross loss
- Max drawdown
- 32.08%
- −$320.76
One run with the author's default settings, $1,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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
7 settings have no label
In the settings dialog Period (line 5), BuyZone (line 6), SellZone (line 7), risk (line 50), leverage (line 51), sl (line 73), tp (line 74) 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 53, 54. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 22
iff() on line 22, 23, 37, 38, 42, 43, 44, 45. v5 writes it as the ternary c ? a : b.
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 abs → math.abs, stdev → ta.stdev, crossover → ta.crossover, crossunder → ta.crossunder, round → math.round, pow → math.pow.
- 2 strategy calls use the when = argument (line 53, 54). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 1: //@version=4 → //@version=5
- Line 22: iff(c, a, b) → (c ? a : b)
- Line 22: abs → math.abs
- Line 23: iff(c, a, b) → (c ? a : b)
- Line 23: abs → math.abs
- Line 36: stdev → ta.stdev
12 more edits
- Line 37: iff(c, a, b) → (c ? a : b)
- Line 38: iff(c, a, b) → (c ? a : b)
- Line 42: iff(c, a, b) → (c ? a : b)
- Line 43: iff(c, a, b) → (c ? a : b)
- Line 44: iff(c, a, b) → (c ? a : b)
- Line 45: iff(c, a, b) → (c ? a : b)
- Line 47: crossover → ta.crossover
- Line 48: crossunder → ta.crossunder
- Line 49: round → math.round
- Line 49: pow → math.pow
- Line 49: pow → math.pow
- Line 53: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
-//@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/⋯calc_rsi_volume(fv, length) => - up=iff(fv>fv[1],abs(fv-fv[1])*volume,0)+ up=(fv>fv[1] ? math.abs(fv-fv[1])*volume : 0)- dn=iff(fv<fv[1],abs(fv-fv[1])*volume,0)+ dn=(fv<fv[1] ? math.abs(fv-fv[1])*volume : 0) upt=WiMA(up,length)⋯xPrice = close-StdDev = stdev(xPrice, Period)+StdDev = ta.stdev(xPrice, Period)-d = iff(close > close[1], 0, StdDev)+d = (close > close[1] ? 0 : StdDev)-u = iff(close > close[1], StdDev, 0)+u = (close > close[1] ? StdDev : 0)nU := (13 * nz(nU[1],0) + u) / 14⋯nRes := 100 * nU / (nU + nD)-pos := iff(nRes < BuyZone, -1,- iff(nRes > SellZone, 1, nz(pos[1], 0))) +pos := (nRes < BuyZone ? -1 : (nRes > SellZone ? 1 : nz(pos[1], 0))) -possig := iff(reverse and pos == 1, -1,- iff(reverse and pos == -1, 1, pos)) +possig := (reverse and pos == 1 ? -1 : (reverse and pos == -1 ? 1 : pos)) -long=crossover (rsi_v,ob) and (possig == 1) +long=ta.crossover (rsi_v,ob) and (possig == 1) -short=crossunder(rsi_v,os) and (possig == -1)+short=ta.crossunder(rsi_v,os) and (possig == -1)-g(v, p) => round(v * (pow(10, p))) / pow(10, p)+g(v, p) => math.round(v * (math.pow(10, p))) / math.pow(10, p)risk = input(100)⋯c = g((strategy.equity * leverage / open) * (risk / 100), 4)-strategy.entry("long",1,c,when=long)+strategy.entry("long",strategy.long,c,when=long)strategy.close("long",when=short)⋯Same 2 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 34: input() → input.bool()
- Line 48: input() → input.int()
- Line 49: input() → input.float()
4 more edits
- Line 51: when = long → if block
- Line 52: when = short → if block
- Line 71: input() → input.float()
- Line 72: input() → input.float()
⋯strategy(title="Crypto RSI + RVI Strategy", overlay=true, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.03, pyramiding=1 )-Period = input(100, minval=1)+Period = input.int(100, minval=1)-BuyZone = input(49, minval=1)+BuyZone = input.int(49, minval=1)-SellZone = input(50, minval=1)+SellZone = input.int(50, minval=1)length=Period⋯ -reverse = input(false, title="Trade reverse")+reverse = input.bool(false, title="Trade reverse")xPrice = close⋯g(v, p) => math.round(v * (math.pow(10, p))) / math.pow(10, p)-risk = input(100)+risk = input.int(100)-leverage = input(2.5)+leverage = input.float(2.5)c = g((strategy.equity * leverage / open) * (risk / 100), 4)-strategy.entry("long",strategy.long,c,when=long)+if long+ strategy.entry("long",strategy.long,c)-strategy.close("long",when=short)+if short+ strategy.close("long")//strategy.entry("short",0,when=short)⋯//plotshape(exitLongCondition, style=shape.labeldown, location=location.abovebar, color=color.color.red, size=size.tiny, title="SELL", text="SELL", textcolor=color.color.white)-sl=input(0.2)+sl=input.float(0.2)-tp=input(1.0)+tp=input.float(1.0)strategy.exit("long_tp/sl", "long", profit=close * tp / syminfo.mintick, loss=close * sl / syminfo.mintick, comment='long_tp/sl', alert_message = 'closelong')⋯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: 2 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.
-//@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 |
|---|---|---|---|
| Period (no label in the script) | 100 | int · min 1 | length StdDev |
| Buy Zone (no label in the script) | 49 | int · min 1 | pos os |
| Sell Zone (no label in the script) | 50 | int · min 1 | pos ob |
| Trade reverse | false | bool | possig |
| Risk (no label in the script) | 100 | int | c |
| Leverage (no label in the script) | 2.5 | float | c |
| Sl (no label in the script) | 0.2 | float | exit long_tp/sl exit short_tp/sl |
| Tp (no label in the script) | 1.0 | float | exit long_tp/sl exit short_tp/sl |
What it calculates
- Stdev (
stdev,ta.stdevin v5)xPrice, Period (100)StdDev · line 36
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 | longcrossover (rsi_v,ob) and (possig == 1) | On | 53 |
| Close long | shortcrossunder(rsi_v,os) and (possig == -1) | On | 54 |
| Exit long_tp/sl stop and limit | every bar | On | 75 |
| Exit short_tp/sl stop and limit | every bar | On | 76 |
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.
- 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 | +4.0% | +102.5% | 2 | 50% | 1.29 | 32.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +48.2% | +5.5% | 3 | 33% | 5.72 | 12.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −50.3% | +9.8% | 3 | 33% | 0.18 | 54.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.1% | +8.4% | 0 | 0% | 0.00 | 9.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −71.2% | +16.7% | 4 | 25% | 0.10 | 77.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +74.7% | +21.5% | 3 | 33% | 3.93 | 11.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −85.6% | +148.3% | 6 | 0% | 0.00 | 86.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +18.6% | +17.1% | 3 | 33% | 1.62 | 32.6% | 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 | 0 | — | $0.00 |
| Sideways market | 2 | 50% | $40.74 |
| 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?
13.8%
The 95th percentile of the worst drawdown when the same 2 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 13.8% to 13.8%; the tick is what actually happened, 13.8%. Order luck alone moves it this much.
All 2 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 Jul 2024 65,044.00 | 3 Aug 2024 61,498.30 | 17 | −$138.33 |
| long | 30 Oct 2024 72,736.40 | 11 Mar 2025 78,595.90 | 132 | $179.07 |
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 RSI with RVI Strategy this page | — | v4 strategy | +4.0% | 2 | 32.1% |
| Simple way to BEAT the market [STRATEGY] by TraderHalai | stdev | v4 strategy | +193.5% | 15 | 39.2% |
| Portfolio Performance - 2 Assets by Skywalking2874 | stdev | v5 strategy | No trades on this market | ||
| Historical Volatility by Zeal Terminal | stdev | v5 indicator | indicator | ||
| Double Bollinger Binary Options by Trade_by_DB | stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | stdev | v4 strategy | −20.4% | 7 | 22.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | With a workaround 1,000 bars in 48 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 53) 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/// © exlux99strategy(title="Crypto RSI + RVI Strategy", overlay=true, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.03, pyramiding=1 )Period = input(100, minval=1)BuyZone = input(49, minval=1)SellZone = input(50, minval=1)length=PeriodMA_s=0.0pos=0.0possig=0.0nU=0.0nD=0.0nRes=0.0ob=SellZoneos=BuyZoneWiMA(src, length) => MA_s=0.0 MA_s:=(src + nz(MA_s[1] * (length-1)))/length MA_scalc_rsi_volume(fv, length) => up=iff(fv>fv[1],abs(fv-fv[1])*volume,0) dn=iff(fv<fv[1],abs(fv-fv[1])*volume,0) upt=WiMA(up,length) dnt=WiMA(dn,length) 100*(upt/(upt+dnt))rsi_v = calc_rsi_volume(close, length)// u=plot(ob)// l=plot(os)// fill(u,l,color.red)// plot(50)// plot(rsi_v, color=color.red, linewidth=1) reverse = input(false, title="Trade reverse")xPrice = closeStdDev = stdev(xPrice, Period)d = iff(close > close[1], 0, StdDev)u = iff(close > close[1], StdDev, 0)nU := (13 * nz(nU[1],0) + u) / 14nD := (13 * nz(nD[1],0) + d) / 14nRes := 100 * nU / (nU + nD)pos := iff(nRes < BuyZone, -1, iff(nRes > SellZone, 1, nz(pos[1], 0))) possig := iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos)) long=crossover (rsi_v,ob) and (possig == 1) short=crossunder(rsi_v,os) and (possig == -1)g(v, p) => round(v * (pow(10, p))) / pow(10, p)risk = input(100)leverage = input(2.5)c = g((strategy.equity * leverage / open) * (risk / 100), 4)strategy.entry("long",1,c,when=long)strategy.close("long",when=short)//strategy.entry("short",0,when=short) // ------------------------- Strategy Logic --------------------------------- //var longOpeneda = falsevar shortOpeneda = falsevar int timeOfBuya = na longCondition= long and not longOpeneda if longCondition longOpeneda := true timeOfBuya := timelongExitSignala = shortexitLongCondition = longOpeneda[1] and longExitSignalaif exitLongCondition longOpeneda := false timeOfBuya := na//plotshape(longCondition, style=shape.labelup, location=location.belowbar, color=color.color.green, size=size.tiny, title="BUY", text="BUY", textcolor=color.color.white)//plotshape(exitLongCondition, style=shape.labeldown, location=location.abovebar, color=color.color.red, size=size.tiny, title="SELL", text="SELL", textcolor=color.color.white)sl=input(0.2)tp=input(1.0)strategy.exit("long_tp/sl", "long", profit=close * tp / syminfo.mintick, loss=close * sl / syminfo.mintick, comment='long_tp/sl', alert_message = 'closelong')strategy.exit("short_tp/sl", "short", profit=close * tp / syminfo.mintick, loss=close * sl / syminfo.mintick, comment='short_tp/sl', alert_message = 'closeshort')