Pine Script v4 · Strategy
Weis BB Strategy
A Pine Script v4 strategy built on SMA (close, 14) and Stdev (close, 14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 10% of equity and pays no commission. 11 settings; defaults include Max Intraday Loss(%) 1, Renko Assignment Method ATR and Value 14.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 Weis BB Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
- How did Weis BB Strategy do on BTCUSDT 1D with default settings?
- −1.00%
- From 26 Jan 2024 to 21 Oct 2026, over 32 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Weis BB Strategy be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Weis BB Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 56, 57.
- Does Weis BB Strategy run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 48 ms, in the browser.
BTCUSDT · 1D · default settings
- Wave Volume
- Basis
- Upper
- Lower
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −1.00%
- −$1,000.37
- Buy and hold
- +102.5%
- same period
- Closed trades
- 32
- 11 won · 21 lost
- Profitable
- 34.4%
- of closed trades
- Profit factor
- 0.94
- gross profit ÷ gross loss
- Max drawdown
- 8.69%
- −$8,926.99
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 commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
1 setting has no label
In the settings dialog length (line 38) shows 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 56, 57. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 37
transp = on line 37. v5 folds the transparency into the colour with color.new(c, transp).
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 atr → ta.atr, round → math.round, change → ta.change, sma → ta.sma, stdev → ta.stdev.
- 2 strategy calls use the when = argument (line 56, 57). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 32 before, 32 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 5: input(type = input.float) → input.float()
- Line 7: method is reserved in v5: renamed method_
- Line 8: input(type = input.float) → input.float()
- Line 13: input(type = input.bool) → input.bool()
- Line 14: input(type = input.bool) → input.bool()
8 more edits
- Line 15: tr → ta.tr
- Line 20: atr → ta.atr
- Line 20: round → math.round
- Line 30: change → ta.change
- Line 37: transp = 75 → color.new(directionIsUp ? color.green : color.red, 75)
- Line 41: sma → ta.sma
- Line 42: stdev → ta.stdev
- Line 45: input(type = input.integer) → input.int()
⋯// © sharatgbhat-//@version=4+//@version=5strategy("Weis BB Strategy", overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 10,max_lines_count = 500, max_labels_count = 500)-maxIdLossPcnt = input(1, "Max Intraday Loss(%)", type=input.float)+maxIdLossPcnt = input.float(1, "Max Intraday Loss(%)")strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)-method = input(defval="ATR", options=["ATR", "Traditional", "Part of Price"], title="Renko Assignment Method")+method_ = input(defval="ATR", options=["ATR", "Traditional", "Part of Price"], title="Renko Assignment Method")-methodvalue = input(defval=14.0, type=input.float, minval=0, title="Value")+methodvalue = input.float(defval=14.0, minval=0, title="Value")pricesource = input(defval="Close", options=["Close", "Open / Close", "High / Low"], title="Price Source")⋯useTrueRange = input(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")-isOscillating = input(defval=false, type=input.bool, title="Oscillating")+isOscillating = input.bool(defval=false, title="Oscillating")-normalize = input(defval=false, type=input.bool, title="Normalize")+normalize = input.bool(defval=false, title="Normalize")-vol = useTrueRange == "Always" or useTrueRange == "Auto" and na(volume) ? tr : volume+vol = useTrueRange == "Always" or useTrueRange == "Auto" and na(volume) ? ta.tr : volumeop = useClose ? close : open⋯lo = useOpenClose ? close <= op ? close : op : low-if method == "ATR"+if method_ == "ATR"- methodvalue := atr(round(methodvalue))+ methodvalue := ta.atr(math.round(methodvalue))-if method == "Part of Price"+if method_ == "Part of Price" methodvalue := close / methodvalue⋯direction := currclose > prevclose ? 1 : currclose < prevclose ? -1 : nz(direction[1])-directionHasChanged = change(direction) != 0+directionHasChanged = ta.change(direction) != 0directionIsUp = direction > 0⋯res = barcount > 1 ? vol / barcount : vol-plot(isOscillating and directionIsDown ? -res : res, style=plot.style_columns, color=directionIsUp ? color.green : color.red, transp=75, linewidth=3, title="Wave Volume")+plot(isOscillating and directionIsDown ? -res : res, style=plot.style_columns, color=color.new(directionIsUp ? color.green : color.red, 75), linewidth=3, title="Wave Volume")length = input(14, minval=1)⋯mult = input(2, minval=0.001, maxval=50, title="StdDev")-basis = sma(src, length)+basis = ta.sma(src, length)-dev = mult * stdev(src, length)+dev = mult * ta.stdev(src, length)upper = basis + devlower = basis - dev-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)⋯Clean v5
VerifiedSame 32 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.string()
- Line 9: input() → input.string()
- Line 12: input() → input.string()
- Line 38: input() → input.int()
- Line 39: input() → input.source()
- Line 40: input() → input.int()
- Line 56: when = directionIsDown → if block
- Line 57: when = directionIsUp → if block
⋯strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)-method_ = input(defval="ATR", options=["ATR", "Traditional", "Part of Price"], title="Renko Assignment Method")+method_ = input.string(defval="ATR", options=["ATR", "Traditional", "Part of Price"], title="Renko Assignment Method")methodvalue = input.float(defval=14.0, minval=0, title="Value")-pricesource = input(defval="Close", options=["Close", "Open / Close", "High / Low"], title="Price Source")+pricesource = input.string(defval="Close", options=["Close", "Open / Close", "High / Low"], title="Price Source")useClose = pricesource == "Close"useOpenClose = pricesource == "Open / Close" or useClose-useTrueRange = input(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")+useTrueRange = input.string(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")isOscillating = input.bool(defval=false, title="Oscillating")⋯plot(isOscillating and directionIsDown ? -res : res, style=plot.style_columns, color=color.new(directionIsUp ? color.green : color.red, 75), linewidth=3, title="Wave Volume")-length = input(14, minval=1)+length = input.int(14, minval=1)-src = input(close, title="Source")+src = input.source(close, title="Source")-mult = input(2, minval=0.001, maxval=50, title="StdDev")+mult = input.int(2, minval=0.001, maxval=50, title="StdDev")basis = ta.sma(src, length)⋯ strategy.entry("Sell", strategy.short)- strategy.exit("exit","Buy",when=directionIsDown,qty_percent=100,profit=20,loss=10)+ if directionIsDown+ strategy.exit("exit","Buy",qty_percent=100,profit=20,loss=10)- strategy.exit("exit","Sell",when=directionIsUp,qty_percent=100,profit=20,loss=10)+ if directionIsUp+ strategy.exit("exit","Sell",qty_percent=100,profit=20,loss=10)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: 32 before, 32 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.
⋯// © sharatgbhat-//@version=5+//@version=6strategy("Weis BB Strategy", overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 10,max_lines_count = 500, max_labels_count = 500)⋯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 |
|---|---|---|---|
| Max Intraday Loss(%) | 1 | float | line 6 |
| Renko Assignment Method | ATR | string · options ["ATR", "Traditional", "Part of Price"] | line 19 line 21 |
| Value | 14.0 | float · min 0 | prevhigh prevlow |
| Price Source | Close | string · options ["Close", "Open / Close", "High / Low"] | useClose useOpenClose |
| Use True Range instead of Volume | Auto | string · options ["Always", "Auto", "Never"] | vol |
| Oscillating | false | bool | Wave Volume |
| Normalize | false | bool | barcount |
| Length (no label in the script) | 14 | int · min 1 | basis dev |
| Source | close | source | basis dev |
| StdDev | 2 | int · min 0.001 · max 50 | dev |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | Upper Lower Basis |
What it calculates
- SMA (
sma,ta.smain v5)Source (close), Length (14)basis · line 41 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (14)dev · line 42
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 Buy long | (MomentumBull and directionIsUp) | On | 53 |
| Open Sell short | (MomentumBear and directionIsDown) | On | 55 |
| Exit exit stop and limit | directionIsDowndirection < 0 | On | 56 |
| Exit exit stop and limit | directionIsUpdirection > 0 | On | 57 |
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 | −1.0% | +102.5% | 32 | 34% | 0.94 | 8.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.2% | +5.5% | 34 | 29% | 0.96 | 2.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −5.8% | +9.8% | 43 | 42% | 0.78 | 14.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.1% | +8.4% | 32 | 28% | 0.99 | 4.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −18.6% | +16.7% | 48 | 35% | 0.39 | 18.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.2% | +21.5% | 31 | 35% | 1.17 | 2.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −6.1% | +148.3% | 32 | 25% | 0.70 | 12.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −1.4% | +17.1% | 28 | 29% | 0.70 | 2.8% | 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 | 9 | 33% | −$359.14 |
| Sideways market | 16 | 31% | $893.75 |
| Falling market | 7 | 43% | −$1,534.98 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
9.4%
The 95th percentile of the worst drawdown when the same 32 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 4.2% to 9.4%; the tick is what actually happened, 7.7%. Order luck alone moves it this much.
All 32 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 9 Feb 2024 45,288.70 | 28 Feb 2024 57,731.80 | 19 | $2,747.52 |
| long | 29 Feb 2024 62,432.10 | 20 Mar 2024 61,937.40 | 20 | −$81.42 |
| short | 20 Mar 2024 61,937.40 | 20 Mar 2024 62,328.80 | 0 | −$64.87 |
| short | 14 Apr 2024 63,924.50 | 16 May 2024 66,206.50 | 32 | −$366.27 |
| long | 16 May 2024 66,206.50 | 25 Jun 2024 60,293.30 | 40 | −$913.11 |
| short | 25 Jun 2024 60,293.30 | 16 Jul 2024 64,724.10 | 21 | −$744.58 |
| long | 16 Jul 2024 64,724.10 | 3 Aug 2024 61,498.30 | 18 | −$501.26 |
| short | 3 Aug 2024 61,498.30 | 24 Aug 2024 64,037.20 | 21 | −$413.15 |
| long | 24 Aug 2024 64,037.20 | 2 Oct 2024 60,804.90 | 39 | −$503.06 |
| short | 2 Oct 2024 60,804.90 | 15 Oct 2024 66,084.00 | 13 | −$860.89 |
| long | 15 Oct 2024 66,084.00 | 11 Nov 2024 81,813.90 | 27 | $2,339.81 |
| long | 12 Nov 2024 88,648.00 | 3 Feb 2025 97,700.60 | 83 | $1,027.71 |
| short | 3 Feb 2025 97,700.60 | 25 Mar 2025 87,498.20 | 50 | $1,061.66 |
| long | 25 Mar 2025 87,498.20 | 7 Apr 2025 78,430.00 | 13 | −$1,064.66 |
| short | 7 Apr 2025 78,430.00 | 23 Apr 2025 93,443.00 | 16 | −$1,946.03 |
| long | 23 Apr 2025 93,443.00 | 6 Jun 2025 101,509.00 | 44 | $860.73 |
| short | 6 Jun 2025 101,509.00 | 10 Jun 2025 110,263.00 | 4 | −$867.41 |
| long | 10 Jun 2025 110,263.00 | 1 Aug 2025 115,764.00 | 52 | $497.46 |
| short | 1 Aug 2025 115,764.00 | 14 Aug 2025 123,306.00 | 13 | −$652.89 |
| long | 14 Aug 2025 123,306.00 | 20 Aug 2025 112,873.00 | 6 | −$842.38 |
| short | 20 Aug 2025 112,873.00 | 11 Sep 2025 113,960.00 | 22 | −$95.07 |
| long | 11 Sep 2025 113,960.00 | 24 Sep 2025 111,999.00 | 13 | −$169.72 |
| short | 24 Sep 2025 111,999.00 | 3 Oct 2025 120,529.00 | 9 | −$749.84 |
| long | 3 Oct 2025 120,529.00 | 5 Nov 2025 101,497.00 | 33 | −$1,542.70 |
| short | 5 Nov 2025 101,497.00 | 3 Jan 2026 89,995.10 | 59 | $1,089.68 |
| long | 3 Jan 2026 89,995.10 | 1 Feb 2026 78,741.10 | 29 | −$1,216.07 |
| short | 1 Feb 2026 78,741.10 | 5 Feb 2026 70,942.30 | 4 | $951.11 |
| short | 6 Feb 2026 62,909.90 | 6 Feb 2026 69,200.90 | 0 | −$969.80 |
| short | 24 Feb 2026 64,656.00 | 5 Mar 2026 72,666.80 | 9 | −$1,189.55 |
| long | 5 Mar 2026 72,666.80 | 18 May 2026 77,457.70 | 74 | $625.15 |
| short | 18 May 2026 77,457.70 | 22 Jul 2026 66,556.10 | 65 | $1,343.32 |
| long | 22 Jul 2026 66,556.10 | 9 Oct 2026 81,754.50 | 79 | $2,210.22 |
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 |
|---|---|---|---|---|---|
| Weis BB Strategy this page | — | v4 strategy | −1.0% | 32 | 8.7% |
| 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 | ||
| P-Signal Strategy by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.6% |
| P-Signal Strategy & Alert by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | Yes 1,000 bars in 48 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/// © sharatgbhat//@version=4strategy("Weis BB Strategy", overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 10,max_lines_count = 500, max_labels_count = 500)maxIdLossPcnt = input(1, "Max Intraday Loss(%)", type=input.float)strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)method = input(defval="ATR", options=["ATR", "Traditional", "Part of Price"], title="Renko Assignment Method")methodvalue = input(defval=14.0, type=input.float, minval=0, title="Value")pricesource = input(defval="Close", options=["Close", "Open / Close", "High / Low"], title="Price Source")useClose = pricesource == "Close"useOpenClose = pricesource == "Open / Close" or useCloseuseTrueRange = input(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")isOscillating = input(defval=false, type=input.bool, title="Oscillating")normalize = input(defval=false, type=input.bool, title="Normalize")vol = useTrueRange == "Always" or useTrueRange == "Auto" and na(volume) ? tr : volumeop = useClose ? close : openhi = useOpenClose ? close >= op ? close : op : highlo = useOpenClose ? close <= op ? close : op : lowif method == "ATR" methodvalue := atr(round(methodvalue))if method == "Part of Price" methodvalue := close / methodvaluecurrclose = float(na)prevclose = nz(currclose[1])prevhigh = prevclose + methodvalueprevlow = prevclose - methodvaluecurrclose := hi > prevhigh ? hi : lo < prevlow ? lo : prevclosedirection = int(na)direction := currclose > prevclose ? 1 : currclose < prevclose ? -1 : nz(direction[1])directionHasChanged = change(direction) != 0directionIsUp = direction > 0directionIsDown = direction < 0barcount = 1barcount := not directionHasChanged and normalize ? barcount[1] + barcount : barcountvol := not directionHasChanged ? vol[1] + vol : volres = barcount > 1 ? vol / barcount : volplot(isOscillating and directionIsDown ? -res : res, style=plot.style_columns, color=directionIsUp ? color.green : color.red, transp=75, linewidth=3, title="Wave Volume")length = input(14, minval=1)src = input(close, title="Source")mult = input(2, minval=0.001, maxval=50, title="StdDev")basis = sma(src, length)dev = mult * stdev(src, length)upper = basis + devlower = basis - devoffset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)p1 = plot(upper, "Upper", color=#2962FF, offset = offset)p2 = plot(lower, "Lower", color=#2962FF, offset = offset)fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))MomentumBull = close>upperMomentumBear = close<lowerif (MomentumBull and directionIsUp) strategy.entry("Buy", strategy.long)if (MomentumBear and directionIsDown) strategy.entry("Sell", strategy.short) strategy.exit("exit","Buy",when=directionIsDown,qty_percent=100,profit=20,loss=10) strategy.exit("exit","Sell",when=directionIsUp,qty_percent=100,profit=20,loss=10)