Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (11)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctWave Volume$98,641$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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

Differs

Trades 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

Verified

Same 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.

SettingDefaultType and rangeFeeds
Max Intraday Loss(%)1floatline 6
Renko Assignment MethodATRstring · options ["ATR", "Traditional", "Part of Price"]line 19 line 21
Value14.0float · min 0prevhigh prevlow
Price SourceClosestring · options ["Close", "Open / Close", "High / Low"]useClose useOpenClose
Use True Range instead of VolumeAutostring · options ["Always", "Auto", "Never"]vol
OscillatingfalseboolWave Volume
Normalizefalseboolbarcount
Length (no label in the script)14int · min 1basis dev
Sourceclosesourcebasis dev
StdDev2int · min 0.001 · max 50dev
Offset0int (written input.integer) · min -500 · max 500Upper Lower Basis

What it calculates

  • SMA (sma, ta.sma in v5)Source (close), Length (14)basis · line 41
  • Stdev (stdev, ta.stdev in 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.

closecloseprice datalengthLengthsetting · 14multStdDevsetting · 2volumevolumeprice datauseTrueRangeUse True Range instead …setting · Autoopenopenprice datahighhighprice datalowlowprice datamethodvalueValuesetting · 14.0pricesourcePrice Sourcesetting · ClosebasisSMA→ basisdevStdev→ devvolvolvalueopopvaluehihivaluelolovaluecurrclosecurrclosevalueprevcloseprevclosevalueprevhigh, prevlowprevhigh · prevlow2 valuesdirectiondirectionvaluebarcountbarcountvalueresresvalueupper, lowerupper · lower2 valuesdirectionIsUpdirectionIsUpconditiondirectionIsDowndirectionIsDownconditionMomentumBullMomentumBullconditionMomentumBearMomentumBearconditionuseCloseuseCloseconditionuseOpenCloseuseOpenCloseconditiondirectionHasChangeddirectionHasChangedconditionentry:BuyOpen Buystrategy.entryentry:SellOpen Sellstrategy.entryexit:exitexit exitstrategy.exitplot:37Wave Volumeplotplot:46Basisplotplot:47Upperplotplot:48Lowerplotfill:BackgroundBackgroundfill

Order rules

OrderFires whenBy defaultLine
Open Buy long(MomentumBull and directionIsUp)On53
Open Sell short(MomentumBear and directionIsDown)On55
Exit exit stop and limitdirectionIsDowndirection < 0On56
Exit exit stop and limitdirectionIsUpdirection > 0On57

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.

7/7trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−1.0%+102.5%3234%0.948.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.2%+5.5%3429%0.962.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−5.8%+9.8%4342%0.7814.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%3228%0.994.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−18.6%+16.7%4835%0.3918.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.2%+21.5%3135%1.172.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−6.1%+148.3%3225%0.7012.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−1.4%+17.1%2829%0.702.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 barsTradesWonP&L
Rising market933%−$359.14
Sideways market1631%$893.75
Falling market743%−$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.

0%11%
All 32 trades
SideEntryExitBarsP&L
long9 Feb 2024 45,288.7028 Feb 2024 57,731.8019$2,747.52
long29 Feb 2024 62,432.1020 Mar 2024 61,937.4020−$81.42
short20 Mar 2024 61,937.4020 Mar 2024 62,328.800−$64.87
short14 Apr 2024 63,924.5016 May 2024 66,206.5032−$366.27
long16 May 2024 66,206.5025 Jun 2024 60,293.3040−$913.11
short25 Jun 2024 60,293.3016 Jul 2024 64,724.1021−$744.58
long16 Jul 2024 64,724.103 Aug 2024 61,498.3018−$501.26
short3 Aug 2024 61,498.3024 Aug 2024 64,037.2021−$413.15
long24 Aug 2024 64,037.202 Oct 2024 60,804.9039−$503.06
short2 Oct 2024 60,804.9015 Oct 2024 66,084.0013−$860.89
long15 Oct 2024 66,084.0011 Nov 2024 81,813.9027$2,339.81
long12 Nov 2024 88,648.003 Feb 2025 97,700.6083$1,027.71
short3 Feb 2025 97,700.6025 Mar 2025 87,498.2050$1,061.66
long25 Mar 2025 87,498.207 Apr 2025 78,430.0013−$1,064.66
short7 Apr 2025 78,430.0023 Apr 2025 93,443.0016−$1,946.03
long23 Apr 2025 93,443.006 Jun 2025 101,509.0044$860.73
short6 Jun 2025 101,509.0010 Jun 2025 110,263.004−$867.41
long10 Jun 2025 110,263.001 Aug 2025 115,764.0052$497.46
short1 Aug 2025 115,764.0014 Aug 2025 123,306.0013−$652.89
long14 Aug 2025 123,306.0020 Aug 2025 112,873.006−$842.38
short20 Aug 2025 112,873.0011 Sep 2025 113,960.0022−$95.07
long11 Sep 2025 113,960.0024 Sep 2025 111,999.0013−$169.72
short24 Sep 2025 111,999.003 Oct 2025 120,529.009−$749.84
long3 Oct 2025 120,529.005 Nov 2025 101,497.0033−$1,542.70
short5 Nov 2025 101,497.003 Jan 2026 89,995.1059$1,089.68
long3 Jan 2026 89,995.101 Feb 2026 78,741.1029−$1,216.07
short1 Feb 2026 78,741.105 Feb 2026 70,942.304$951.11
short6 Feb 2026 62,909.906 Feb 2026 69,200.900−$969.80
short24 Feb 2026 64,656.005 Mar 2026 72,666.809−$1,189.55
long5 Mar 2026 72,666.8018 May 2026 77,457.7074$625.15
short18 May 2026 77,457.7022 Jul 2026 66,556.1065$1,343.32
long22 Jul 2026 66,556.109 Oct 2026 81,754.5079$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.

ScriptSharesTypeNetTradesMax drawdown
Weis BB Strategy this page—v4 strategy−1.0%328.7%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%
I11L Long Put-Call Ratio Inversion by I11Lsma stdevv5 strategyNo trades on this market
P-Signal Strategy by Kharevskystdev smav4 strategy−9.7%2934.6%
P-Signal Strategy & Alert by Kharevskystdev smav4 strategy−9.7%2934.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msYes 1,000 bars in 48 msNot measured
PineTSNo 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)