Pine Script v4 · Strategy
BB+RSI+OBV
A Pine Script v4 strategy built on CUM or Change, SMA (source, 20) and Stdev (source, 20). 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. 2 settings; defaults include Length 20 and Mult 2.0.
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 BB+RSI+OBV repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 21 of 21 trades.
- How did BB+RSI+OBV do on BTCUSDT 1D with default settings?
- +52.51%
- From 26 Jan 2024 to 21 Oct 2026, over 71 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can BB+RSI+OBV be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L20:C0: strategy.exit() must specify at least one of profit, limit, loss, stop, trail_price, trail_points, trail_offset. An exit ord…), so no v5 download is offered; the edits are shown below.
- Does BB+RSI+OBV use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does BB+RSI+OBV run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 31 ms, in the browser.
BTCUSDT · 1D · default settings
- CUM
- SMA
- Stdev
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +52.51%
- $52,507.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 71
- 22 won · 49 lost
- Profitable
- 31.0%
- of closed trades
- Profit factor
- 1.45
- gross profit ÷ gross loss
- Max drawdown
- 29.32%
- −$32,288.30
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short 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
No stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
strategy.exit with no exit price stops the upgrade to v5 line 20
strategy.exit on line 20, 22 sets none of profit, limit, loss, stop or a trailing stop. v4 allows that; v5 rejects the call, so the script does not convert to v5 until each call gets one.
-
Note
2 settings have no label
In the settings dialog length (line 9), mult (line 10) 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 19, 20, 21, 22. 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 cum → ta.cum, sign → math.sign, change → ta.change, sma → ta.sma, stdev → ta.stdev, rsi → ta.rsi.
- 4 strategy calls use the when = argument (line 19, 20, 21, 22). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersThe v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L20:C0: strategy.exit() must specify at least one of profit, limit, loss, stop, trail_price, trail_points, trail_offset. An exit order with no condition can never fill.
- Line 3: //@version=4 → //@version=5
- Line 6: cum → ta.cum
- Line 6: sign → math.sign
- Line 6: change → ta.change
- Line 11: sma → ta.sma
- Line 12: stdev → ta.stdev
- Line 15: rsi → ta.rsi
- Line 17: rsi → ta.rsi
⋯// © atakhadivi-//@version=4+//@version=5strategy("BB+RSI+OBV", overlay=true)src = close-obv = cum(sign(change(src)) * volume)+obv = ta.cum(math.sign(ta.change(src)) * volume)// plot(obv, color=#3A6CA8, title="OnBalanceVolume")⋯mult = input(2.0, minval=0.001, maxval=50)-basis = sma(source, length)+basis = ta.sma(source, length)-dev = mult * stdev(source, length)+dev = mult * ta.stdev(source, length)upper = basis + devlower = basis - dev-buyEntry = source > basis and rsi(close, 14) > 50 and obv[1] < obv +buyEntry = source > basis and ta.rsi(close, 14) > 50 and obv[1] < obv buyExit = source < lower-sellEntry = source < basis and rsi(close, 14) < 50 and obv[1] > obv+sellEntry = source < basis and ta.rsi(close, 14) < 50 and obv[1] > obvsellExit = source > upper⋯Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L20:C0: strategy.exit() must specify at least one of profit, limit, loss, stop, trail_price, trail_points, trail_offset. An exit order with no condition can never fill.), so this step could not be checked.
- Line 9: input() → input.int()
- Line 10: input() → input.float()
- Line 19: when = buyEntry → if block
- Line 20: when = buyExit → if block
- Line 21: when = sellEntry → if block
- Line 22: when = sellExit → if block
⋯source = close-length = input(20, minval=1)+length = input.int(20, minval=1)-mult = input(2.0, minval=0.001, maxval=50)+mult = input.float(2.0, minval=0.001, maxval=50)basis = ta.sma(source, length)⋯sellExit = source > upper-strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE", when=buyEntry)+if buyEntry+ strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE")-strategy.exit(id='BBandLE', when=buyExit)+if buyExit+ strategy.exit(id='BBandLE')-strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandSE", when=sellEntry)+if sellEntry+ strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandSE")-strategy.exit(id='BBandSE', when=sellExit)+if sellExit+ strategy.exit(id='BBandSE')Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L22:C4: strategy.exit() must specify at least one of profit, limit, loss, stop, trail_price, trail_points, trail_offset. An exit order with no condition can never fill.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © atakhadivi-//@version=5+//@version=6strategy("BB+RSI+OBV", 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 |
|---|---|---|---|
| Length (no label in the script) | 20 | int · min 1 | basis dev |
| Mult (no label in the script) | 2.0 | float · min 0.001 · max 50 | dev |
What it calculates
- CUM / Change (
cum,ta.cumin v5)sign(change(src)) * volumeobv · line 6 - SMA (
sma,ta.smain v5)source, Length (20)basis · line 11 - Stdev (
stdev,ta.stdevin v5)source, Length (20)dev · line 12
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 BBandLE long | buyEntrysource > basis and rsi(close, 14) > 50 and obv[1] < obv | On | 19 |
| Exit BBandLE | buyExitsource < lower | On | 20 |
| Open BBandSE short | sellEntrysource < basis and rsi(close, 14) < 50 and obv[1] > obv | On | 21 |
| Exit BBandSE | sellExitsource > upper | On | 22 |
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 | +52.5% | +102.5% | 71 | 31% | 1.45 | 29.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.6% | +5.5% | 82 | 26% | 1.03 | 14.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.2% | +9.8% | 69 | 29% | 1.16 | 2.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.6% | +8.4% | 102 | 21% | 0.77 | 1.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 77 | 31% | 0.87 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 78 | 31% | 1.37 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.4% | +148.3% | 71 | 30% | 1.39 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 88 | 30% | 1.03 | 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 | 27 | 30% | −$32,010.60 |
| Sideways market | 27 | 41% | $68,288.60 |
| Falling market | 17 | 18% | $16,229.80 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
38.4%
The 95th percentile of the worst drawdown when the same 71 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 18.1% to 38.4%; the tick is what actually happened, 27.9%. Order luck alone moves it this much.
All 71 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 15 Feb 2024 51,795.20 | 20 Mar 2024 61,937.40 | 34 | $10,142.20 |
| short | 20 Mar 2024 61,937.40 | 21 Mar 2024 67,840.50 | 1 | −$5,903.10 |
| long | 21 Mar 2024 67,840.50 | 23 Mar 2024 63,796.60 | 2 | −$4,043.87 |
| short | 23 Mar 2024 63,796.60 | 26 Mar 2024 69,880.00 | 3 | −$6,083.36 |
| long | 26 Mar 2024 69,880.00 | 3 Apr 2024 65,464.00 | 8 | −$4,416.01 |
| short | 3 Apr 2024 65,464.00 | 5 Apr 2024 68,487.80 | 2 | −$3,023.81 |
| long | 5 Apr 2024 68,487.80 | 13 Apr 2024 67,116.50 | 8 | −$1,371.28 |
| short | 13 Apr 2024 67,116.50 | 23 Apr 2024 66,819.30 | 10 | $297.20 |
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$2,529.74 |
| short | 25 Apr 2024 64,289.60 | 6 May 2024 64,012.00 | 11 | $277.58 |
| long | 6 May 2024 64,012.00 | 7 May 2024 63,165.20 | 1 | −$846.82 |
| short | 7 May 2024 63,165.20 | 16 May 2024 66,206.50 | 9 | −$3,041.33 |
| long | 16 May 2024 66,206.50 | 12 Jun 2024 67,314.20 | 27 | $1,107.72 |
| short | 12 Jun 2024 67,314.20 | 15 Jul 2024 60,797.90 | 33 | $6,516.32 |
| long | 15 Jul 2024 60,797.90 | 1 Aug 2024 64,628.00 | 17 | $3,830.10 |
| short | 1 Aug 2024 64,628.00 | 22 Aug 2024 61,156.00 | 21 | $3,471.98 |
| long | 22 Aug 2024 61,156.00 | 28 Aug 2024 59,415.00 | 6 | −$1,741.03 |
| short | 28 Aug 2024 59,415.00 | 14 Sep 2024 60,498.00 | 17 | −$1,082.99 |
| long | 14 Sep 2024 60,498.00 | 2 Oct 2024 60,804.90 | 18 | $306.93 |
| short | 2 Oct 2024 60,804.90 | 13 Oct 2024 63,206.20 | 11 | −$2,401.31 |
| long | 13 Oct 2024 63,206.20 | 20 Dec 2024 97,461.90 | 68 | $34,255.60 |
| short | 20 Dec 2024 97,461.90 | 4 Jan 2025 98,174.20 | 15 | −$712.31 |
| long | 4 Jan 2025 98,174.20 | 9 Jan 2025 95,060.60 | 5 | −$3,113.56 |
| short | 9 Jan 2025 95,060.60 | 15 Jan 2025 96,560.90 | 6 | −$1,500.24 |
| long | 15 Jan 2025 96,560.90 | 2 Feb 2025 100,636.00 | 18 | $4,074.81 |
| short | 2 Feb 2025 100,636.00 | 21 Feb 2025 98,305.00 | 19 | $2,330.65 |
| long | 21 Feb 2025 98,305.00 | 22 Feb 2025 96,182.00 | 1 | −$2,123.02 |
| short | 22 Feb 2025 96,182.00 | 3 Mar 2025 94,270.00 | 9 | $1,912.00 |
| long | 3 Mar 2025 94,270.00 | 4 Mar 2025 86,221.20 | 1 | −$8,048.83 |
| short | 4 Mar 2025 86,221.20 | 25 Mar 2025 87,498.20 | 21 | −$1,277.00 |
| long | 25 Mar 2025 87,498.20 | 30 Mar 2025 82,648.50 | 5 | −$4,849.63 |
| short | 30 Mar 2025 82,648.50 | 12 Apr 2025 83,423.80 | 13 | −$775.30 |
| long | 12 Apr 2025 83,423.80 | 6 Jun 2025 101,509.00 | 55 | $18,084.90 |
| short | 6 Jun 2025 101,509.00 | 10 Jun 2025 110,263.00 | 4 | −$8,754.33 |
| long | 10 Jun 2025 110,263.00 | 15 Jun 2025 105,415.00 | 5 | −$4,848.39 |
| short | 15 Jun 2025 105,415.00 | 17 Jun 2025 106,795.00 | 2 | −$1,379.90 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$2,243.36 |
| short | 18 Jun 2025 104,551.00 | 24 Jun 2025 105,334.00 | 6 | −$782.77 |
| long | 24 Jun 2025 105,334.00 | 1 Aug 2025 115,764.00 | 38 | $10,430.10 |
| short | 1 Aug 2025 115,764.00 | 8 Aug 2025 117,472.00 | 7 | −$1,707.95 |
| long | 8 Aug 2025 117,472.00 | 19 Aug 2025 116,227.00 | 11 | −$1,244.97 |
| short | 19 Aug 2025 116,227.00 | 23 Aug 2025 116,936.00 | 4 | −$708.95 |
| long | 23 Aug 2025 116,936.00 | 24 Aug 2025 115,438.00 | 1 | −$1,497.94 |
| short | 24 Aug 2025 115,438.00 | 11 Sep 2025 113,960.00 | 18 | $1,478.06 |
| long | 11 Sep 2025 113,960.00 | 23 Sep 2025 112,651.00 | 12 | −$1,309.01 |
| short | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | −$1,660.98 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$1,537.48 |
| short | 11 Oct 2025 112,774.00 | 27 Oct 2025 114,559.00 | 16 | −$1,784.92 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 110,021.00 | 3 | −$4,538.11 |
| short | 30 Oct 2025 110,021.00 | 3 Jan 2026 89,995.10 | 65 | $20,026.20 |
| long | 3 Jan 2026 89,995.10 | 21 Jan 2026 88,427.70 | 18 | −$1,567.48 |
| short | 21 Jan 2026 88,427.70 | 5 Mar 2026 72,666.80 | 43 | $15,760.90 |
| long | 5 Mar 2026 72,666.80 | 8 Mar 2026 67,262.90 | 3 | −$5,403.86 |
| short | 8 Mar 2026 67,262.90 | 11 Mar 2026 69,948.60 | 3 | −$2,685.73 |
| long | 11 Mar 2026 69,948.60 | 20 Mar 2026 69,930.00 | 9 | −$18.63 |
| short | 20 Mar 2026 69,930.00 | 24 Mar 2026 70,906.40 | 4 | −$976.44 |
| long | 24 Mar 2026 70,906.40 | 27 Mar 2026 68,820.30 | 3 | −$2,086.14 |
| short | 27 Mar 2026 68,820.30 | 6 Apr 2026 69,034.20 | 10 | −$213.87 |
| long | 6 Apr 2026 69,034.20 | 17 May 2026 78,148.10 | 41 | $9,113.87 |
| short | 17 May 2026 78,148.10 | 6 Jul 2026 63,650.00 | 50 | $14,498.00 |
| long | 6 Jul 2026 63,650.00 | 25 Jul 2026 64,140.00 | 19 | $489.99 |
| short | 25 Jul 2026 64,140.00 | 26 Jul 2026 64,375.00 | 1 | −$235.01 |
| long | 26 Jul 2026 64,375.00 | 28 Jul 2026 63,755.90 | 2 | −$619.15 |
| short | 28 Jul 2026 63,755.90 | 31 Jul 2026 64,780.00 | 3 | −$1,024.17 |
| long | 31 Jul 2026 64,780.00 | 1 Aug 2026 62,887.90 | 1 | −$1,892.15 |
| short | 1 Aug 2026 62,887.90 | 6 Aug 2026 64,665.20 | 5 | −$1,777.36 |
| long | 6 Aug 2026 64,665.20 | 11 Aug 2026 63,970.00 | 5 | −$695.23 |
| short | 11 Aug 2026 63,970.00 | 18 Aug 2026 64,532.10 | 7 | −$562.10 |
| long | 18 Aug 2026 64,532.10 | 16 Sep 2026 75,644.50 | 29 | $11,112.40 |
| short | 16 Sep 2026 75,644.50 | 19 Sep 2026 80,883.90 | 3 | −$5,239.38 |
| long | 19 Sep 2026 80,883.90 | 9 Oct 2026 81,754.50 | 20 | $870.60 |
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 |
|---|---|---|---|---|---|
| BB+RSI+OBV this page | — | v4 strategy | +52.5% | 71 | 29.3% |
| Crunchster's Normalised Trend Strategy by Crunchster1 | stdev cum sma | v5 strategy | +22.9% | 73 | 10.9% |
| meta-capitulation by serafimovkliment | sma cum | v5 strategy | No trades on this market | ||
| Double Bollinger Binary Options by Trade_by_DB | sma stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | sma stdev | v4 strategy | −20.4% | 7 | 22.3% |
| I11L Long Put-Call Ratio Inversion by I11L | sma stdev | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 31 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“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/// © atakhadivi//@version=4strategy("BB+RSI+OBV", overlay=true)src = closeobv = cum(sign(change(src)) * volume)// plot(obv, color=#3A6CA8, title="OnBalanceVolume")source = closelength = input(20, minval=1)mult = input(2.0, minval=0.001, maxval=50)basis = sma(source, length)dev = mult * stdev(source, length)upper = basis + devlower = basis - devbuyEntry = source > basis and rsi(close, 14) > 50 and obv[1] < obv buyExit = source < lowersellEntry = source < basis and rsi(close, 14) < 50 and obv[1] > obvsellExit = source > upperstrategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE", when=buyEntry)strategy.exit(id='BBandLE', when=buyExit)strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandSE", when=sellEntry)strategy.exit(id='BBandSE', when=sellExit)