Pine Script v4 · Strategy
Bollinger -B Candles Strategy
A Pine Script v4 strategy built on SMA or EMA or HMA or RMA or VWMA or WMA (source, length) and BB (close, 100). 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 commits 10% of equity and pays 0.01% commission. 14 settings; defaults include BBLength 100, Moving Average Type rma and Lookback Period 22.
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 Bollinger -B Candles Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did Bollinger -B Candles Strategy do on BTCUSDT 1D with default settings?
- +17.30%
- From 26 Jan 2024 to 21 Oct 2026, over 29 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Bollinger -B Candles 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 Bollinger -B Candles Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Bollinger -B Candles Strategy run in Zeal Terminal?
- Yes
- It compiles in 36 ms and runs 1,000 bars in 114 ms, in the browser.
BTCUSDT · 1D · default settings
- TrailingStop
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +17.30%
- $1,729.98
- Buy and hold
- +102.5%
- same period
- Closed trades
- 29
- 10 won · 19 lost
- Profitable
- 34.5%
- of closed trades
- Profit factor
- 2.71
- gross profit ÷ gross loss
- Max drawdown
- 5.10%
- −$570.85
One run with the author's default settings, $10,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
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
11 settings have no label
In the settings dialog BBLength (line 5), useMovingAverage (line 7), lookbackPeriod (line 9), colorByPreviousClose (line 10), delaySignalBars (line 11), AtrLength (line 13), AtrMult (line 14), wicks (line 15), considerYearlyHighLow (line 16), considerNewLongTermHighLows (line 17), backtestYears (line 21) 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 99, 100, 101, 102. 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 highest → ta.highest, lowest → ta.lowest, security → request.security, max → math.max, min → math.min, sma → ta.sma, ema → ta.ema, hma → ta.hma, rma → ta.rma, vwma → ta.vwma, wma → ta.wma, bb → ta.bb.
- 4 strategy calls use the when = argument (line 99, 100, 101, 102). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 29 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 24: highest → ta.highest
- Line 24: highest → ta.highest
- Line 25: lowest → ta.lowest
- Line 25: lowest → ta.lowest
- Line 29: security → request.security
25 more edits
- Line 30: security → request.security
- Line 36: max → math.max
- Line 36: max → math.max
- Line 36: min → math.min
- Line 38: min → math.min
- Line 38: min → math.min
- Line 38: max → math.max
- Line 44: sma → ta.sma
- Line 46: ema → ta.ema
- Line 48: hma → ta.hma
- Line 50: rma → ta.rma
- Line 52: vwma → ta.vwma
- Line 54: wma → ta.wma
- Line 59: bb → ta.bb
- Line 60: bb → ta.bb
- Line 61: bb → ta.bb
- Line 62: bb → ta.bb
- Line 75: max → math.max
- Line 75: min → math.min
- Line 80: max → math.max
- Line 83: min → math.min
- Line 93: lowest → ta.lowest
- Line 94: highest → ta.highest
- Line 95: highest → ta.highest
- Line 96: lowest → ta.lowest
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)=>- newHigh = highest(shortHighLowPeriod) == highest(longHighLowPeriod) or not considerNewLongTermHighLows+ newHigh = ta.highest(shortHighLowPeriod) == ta.highest(longHighLowPeriod) or not considerNewLongTermHighLows- newLow = lowest(shortHighLowPeriod) == lowest(longHighLowPeriod) or not considerNewLongTermHighLows+ newLow = ta.lowest(shortHighLowPeriod) == ta.lowest(longHighLowPeriod) or not considerNewLongTermHighLows [newHigh,newLow]⋯f_getYearlyHighLowCondition(considerYearlyHighLow)=>- yhigh = security(syminfo.tickerid, '12M', high[1]) + yhigh = request.security(syminfo.tickerid, '12M', high[1]) - ylow = security(syminfo.tickerid, '12M', low[1]) + ylow = request.security(syminfo.tickerid, '12M', low[1]) yhighlast = yhigh[365]⋯ - yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > max(yhigh,yhighlast) : close > max(yhigh, min(yhighlast, yhighllast))+ yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > math.max(yhigh,yhighlast) : close > math.max(yhigh, math.min(yhighlast, yhighllast)) yearlyHighCondition = ( (na(yhigh) or na(yhighlast) ? true : (yhigh > yhighlast) ) and ( na(yhigh) or na(yhighllast) ? true : (yhigh > yhighllast))) or yearlyTrendUp or not considerYearlyHighLow- yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < min(ylow,ylowlast) : close < min(ylow, max(ylowlast, ylowllast))+ yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < math.min(ylow,ylowlast) : close < math.min(ylow, math.max(ylowlast, ylowllast)) yearlyLowCondition = ( (na(ylow) or na(ylowlast) ? true : (ylow < ylowlast) ) and ( na(ylow) or na(ylowllast) ? true : (ylow < ylowllast))) or yearlyTrendDown or not considerYearlyHighLow⋯f_getMovingAverage(source, MAType, length)=>- ma = sma(source, length)+ ma = ta.sma(source, length) if(MAType == "ema")- ma := ema(source,length)+ ma := ta.ema(source,length) if(MAType == "hma")- ma := hma(source,length)+ ma := ta.hma(source,length) if(MAType == "rma")- ma := rma(source,length)+ ma := ta.rma(source,length) if(MAType == "vwma")- ma := vwma(source,length)+ ma := ta.vwma(source,length) if(MAType == "wma")- ma := wma(source,length)+ ma := ta.wma(source,length) ma⋯[newHighS,newLowS] = f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)-[middleclose, upperclose, lowerclose] = bb(close, BBLength, StdDev)+[middleclose, upperclose, lowerclose] = ta.bb(close, BBLength, StdDev)-[middleopen, upperopen, loweropen] = bb(open, BBLength, StdDev)+[middleopen, upperopen, loweropen] = ta.bb(open, BBLength, StdDev)-[middlehigh, upperhigh, lowerhigh] = bb(high, BBLength, StdDev)+[middlehigh, upperhigh, lowerhigh] = ta.bb(high, BBLength, StdDev)-[middlelow, upperlow, lowerlow] = bb(low, BBLength, StdDev)+[middlelow, upperlow, lowerlow] = ta.bb(low, BBLength, StdDev)percentBClose = (close - lowerclose)*100/(upperclose-lowerclose)⋯newLow = useMovingAverage? percentBMALow : percentBLow-truerange = max(newHigh, newClose[1]) - min(newLow, newClose[1])+truerange = math.max(newHigh, newClose[1]) - math.min(newLow, newClose[1])averagetruerange = f_getMovingAverage(truerange, AtrMAType, AtrLength)⋯longStopPrev = nz(longStop[1], longStop)-longStop := (wicks ? newLow[1] : newClose[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop+longStop := (wicks ? newLow[1] : newClose[1]) > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = newClose + atrshortStopPrev = nz(shortStop[1], shortStop)-shortStop := (wicks ? newHigh[1] : newClose[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+shortStop := (wicks ? newHigh[1] : newClose[1]) < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopdir = 1⋯plot(trailingStop, title="TrailingStop", style=plot.style_linebr, linewidth=1, color= dir == 1 ? color.green : color.red)-buyCondition = lowest(dir,delaySignalBars)==1 and yearlyHighCondition and newHighS+buyCondition = ta.lowest(dir,delaySignalBars)==1 and yearlyHighCondition and newHighS-exitBuyCondition = highest(dir,delaySignalBars) == -1+exitBuyCondition = ta.highest(dir,delaySignalBars) == -1-sellCondition = highest(dir,delaySignalBars) == -1 and yearlyLowCondition and newLowS+sellCondition = ta.highest(dir,delaySignalBars) == -1 and yearlyLowCondition and newLowS-exitSellCondition = lowest(dir,delaySignalBars) == 1+exitSellCondition = ta.lowest(dir,delaySignalBars) == 1strategy.risk.allow_entry_in(tradeDirection)⋯Same 29 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 7: input() → input.bool()
- Line 8: input() → input.string()
- Line 9: input() → input.int()
- Line 10: input() → input.bool()
- Line 11: input() → input.int()
11 more edits
- Line 12: input() → input.string()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.bool()
- Line 16: input() → input.bool()
- Line 17: input() → input.bool()
- Line 21: input() → input.int()
- Line 99: when = buyCondition and inDateRange → if block
- Line 100: when = exitBuyCondition → if block
- Line 101: when = sellCondition and inDateRange → if block
- Line 102: when = exitSellCondition → if block
⋯strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)-BBLength = input(100, minval=1, step=1)+BBLength = input.int(100, minval=1, step=1)StdDev = 10-useMovingAverage = input(true)+useMovingAverage = input.bool(true)-MAType = input(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+MAType = input.string(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-lookbackPeriod = input(22, minval=10, step=10)+lookbackPeriod = input.int(22, minval=10, step=10)-colorByPreviousClose = input(true)+colorByPreviousClose = input.bool(true)-delaySignalBars = input(2, minval=2)+delaySignalBars = input.int(2, minval=2)-AtrMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+AtrMAType = input.string(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-AtrLength = input(10)+AtrLength = input.int(10)-AtrMult = input(4)+AtrMult = input.int(4)-wicks = input(false)+wicks = input.bool(false)-considerYearlyHighLow = input(false)+considerYearlyHighLow = input.bool(false)-considerNewLongTermHighLows = input(false)+considerNewLongTermHighLows = input.bool(false)shortHighLowPeriod = 100⋯tradeDirection = input(title="Trade Direction", defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])-backtestYears = input(10, minval=1, step=1)+backtestYears = input.int(10, minval=1, step=1)//////////////////////////////////// Calculate new high low condition //////////////////////////////////////////////////⋯barcolor(buyCondition? color.lime : sellCondition ? color.orange : color.silver)-strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.none)+if buyCondition and inDateRange+ strategy.entry("Buy", strategy.long, oca_name="oca_buy", oca_type=strategy.oca.none)-strategy.close("Buy", when=exitBuyCondition)+if exitBuyCondition+ strategy.close("Buy")-strategy.entry("Sell", strategy.short, when=sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.none)+if sellCondition and inDateRange+ strategy.entry("Sell", strategy.short, oca_name="oca_sell", oca_type=strategy.oca.none)-strategy.close("Sell", when=exitSellCondition)+if exitSellCondition+ strategy.close("Sell")Does it run in Pine Script v6?
Yes
Same 29 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯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 |
|---|---|---|---|
| BBLength (no label in the script) | 100 | int · min 1 · step 1 | middleclose upperclose lowerclose middleopen upperopen loweropen middlehigh upperhigh lowerhigh middlelow upperlow lowerlow |
| Use Moving Average (no label in the script) | true | bool | newHigh newLow newOpen newClose |
| Moving Average Type | rma | string · options ["ema", "sma", "hma", "rma", "vwma", "wma"] | percentBMAClose percentBMAOpen percentBMAHigh percentBMALow line 45 line 47 line 49 line 51 line 53 |
| Lookback Period (no label in the script) | 22 | int · min 10 · step 10 | percentBMAClose percentBMAOpen percentBMAHigh percentBMALow |
| Color By Previous Close (no label in the script) | true | bool | candleColor |
| Delay Signal Bars (no label in the script) | 2 | int · min 2 | buyCondition exitBuyCondition sellCondition exitSellCondition |
| Moving Average Type | hma | string · options ["ema", "sma", "hma", "rma", "vwma", "wma"] | averagetruerange |
| ATR Length (no label in the script) | 10 | int | averagetruerange |
| ATR Mult (no label in the script) | 4 | int | atr |
| Wicks (no label in the script) | false | bool | longStop shortStop dir |
| Consider Yearly High Low (no label in the script) | false | bool | yearlyHighCondition yearlyLowCondition |
| Consider New Long Term High Lows (no label in the script) | false | bool | newHighS newLowS newHigh newLow |
| Trade Direction | strategy.direction.all | value · options [strategy.direction.all, strategy.direction.long, strategy.direction.short] | line 97 |
| Backtest Years (no label in the script) | 10 | int · min 1 · step 1 | inDateRange |
What it calculates
- SMA / EMA / HMA / RMA / VWMA / WMA (
sma,ta.smain v5)source, lengthma · line 44 - BB (
bb,ta.bbin v5)close, BBLength (100), StdDevmiddleclose · line 59 - BB (
bb,ta.bbin v5)close, BBLength (100), StdDevupperclose · line 59 - BB (
bb,ta.bbin v5)close, BBLength (100), StdDevlowerclose · line 59 - BB (
bb,ta.bbin v5)open, BBLength (100), StdDevmiddleopen · line 60 - BB (
bb,ta.bbin v5)open, BBLength (100), StdDevupperopen · line 60 - BB (
bb,ta.bbin v5)open, BBLength (100), StdDevloweropen · line 60 - BB (
bb,ta.bbin v5)high, BBLength (100), StdDevmiddlehigh · line 61 - BB (
bb,ta.bbin v5)high, BBLength (100), StdDevupperhigh · line 61 - BB (
bb,ta.bbin v5)high, BBLength (100), StdDevlowerhigh · line 61 - BB (
bb,ta.bbin v5)low, BBLength (100), StdDevmiddlelow · line 62 - BB (
bb,ta.bbin v5)low, BBLength (100), StdDevupperlow · line 62 - BB (
bb,ta.bbin v5)low, BBLength (100), StdDevlowerlow · line 62
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.
The script has 67 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Buy long | buyCondition and inDateRange | On | 99 |
| Close Buy | exitBuyConditionhighest(dir,delaySignalBars) == -1 | On | 100 |
| Open Sell short | sellCondition and inDateRange | On | 101 |
| Close Sell | exitSellConditionlowest(dir,delaySignalBars) == 1 | On | 102 |
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 data2 security call(s), none with lookahead on.
- 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 | +17.3% | +102.5% | 29 | 34% | 2.71 | 5.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.0% | +5.5% | 36 | 39% | 1.22 | 2.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +22.3% | +9.8% | 33 | 45% | 2.38 | 4.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.4% | +8.4% | 38 | 24% | 0.95 | 3.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +16.0% | +16.7% | 41 | 32% | 1.73 | 7.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +2.7% | +21.5% | 32 | 44% | 1.38 | 1.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +17.7% | +148.3% | 33 | 45% | 2.70 | 4.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.7% | +17.1% | 38 | 24% | 0.85 | 1.6% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT 12M (aggregated from Binance BTCUSDT 1M), fetched from Binance's public market data for each market.
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 | 5 | 20% | −$141.46 |
| Sideways market | 18 | 39% | $1,728.85 |
| Falling market | 6 | 33% | $142.71 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.1%
The 95th percentile of the worst drawdown when the same 29 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.1% to 5.1%; the tick is what actually happened, 4.1%. Order luck alone moves it this much.
All 29 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 28 Jan 2024 42,120.60 | 13 Jun 2024 68,264.00 | 137 | $620.35 |
| short | 13 Jun 2024 68,264.00 | 16 Jul 2024 64,724.10 | 33 | $54.86 |
| long | 16 Jul 2024 64,724.10 | 4 Aug 2024 60,698.00 | 19 | −$66.60 |
| short | 4 Aug 2024 60,698.00 | 25 Aug 2024 64,157.00 | 21 | −$60.67 |
| long | 25 Aug 2024 64,157.00 | 2 Sep 2024 57,301.80 | 8 | −$112.90 |
| short | 2 Sep 2024 57,301.80 | 14 Sep 2024 60,498.00 | 12 | −$58.41 |
| long | 14 Sep 2024 60,498.00 | 11 Oct 2024 60,326.40 | 27 | −$3.15 |
| short | 11 Oct 2024 60,326.40 | 13 Oct 2024 63,206.20 | 2 | −$49.73 |
| long | 13 Oct 2024 63,206.20 | 10 Dec 2024 97,276.50 | 58 | $556.17 |
| short | 10 Dec 2024 97,276.50 | 26 Mar 2025 87,392.90 | 106 | $110.33 |
| long | 26 Mar 2025 87,392.90 | 30 Mar 2025 82,648.50 | 4 | −$59.87 |
| short | 30 Mar 2025 82,648.50 | 5 Apr 2025 83,889.90 | 6 | −$16.64 |
| long | 5 Apr 2025 83,889.90 | 8 Apr 2025 79,163.20 | 3 | −$61.70 |
| short | 8 Apr 2025 79,163.20 | 11 Apr 2025 79,607.30 | 3 | −$6.30 |
| long | 11 Apr 2025 79,607.30 | 19 Jun 2025 104,887.00 | 69 | $344.13 |
| short | 19 Jun 2025 104,887.00 | 11 Jul 2025 116,010.00 | 22 | −$118.89 |
| long | 11 Jul 2025 116,010.00 | 2 Aug 2025 113,298.00 | 22 | −$26.10 |
| short | 2 Aug 2025 113,298.00 | 12 Aug 2025 118,686.00 | 10 | −$52.75 |
| long | 12 Aug 2025 118,686.00 | 20 Aug 2025 112,873.00 | 8 | −$54.05 |
| short | 20 Aug 2025 112,873.00 | 17 Sep 2025 116,789.00 | 28 | −$38.17 |
| long | 17 Sep 2025 116,789.00 | 23 Sep 2025 112,651.00 | 6 | −$38.83 |
| short | 23 Sep 2025 112,651.00 | 3 Oct 2025 120,529.00 | 10 | −$76.18 |
| long | 3 Oct 2025 120,529.00 | 13 Oct 2025 114,959.00 | 10 | −$50.05 |
| short | 13 Oct 2025 114,959.00 | 6 Dec 2025 89,330.00 | 54 | $239.11 |
| long | 6 Dec 2025 89,330.00 | 31 Jan 2026 84,260.50 | 56 | −$62.49 |
| short | 31 Jan 2026 84,260.50 | 27 Feb 2026 67,485.20 | 27 | $217.02 |
| long | 27 Feb 2026 67,485.20 | 28 May 2026 74,449.30 | 90 | $114.60 |
| short | 28 May 2026 74,449.30 | 6 Jul 2026 63,650.00 | 39 | $162.87 |
| long | 6 Jul 2026 63,650.00 | 9 Oct 2026 81,754.50 | 95 | $324.14 |
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 |
|---|---|---|---|---|---|
| Bollinger -B Candles Strategy this page | — | v4 strategy | +17.3% | 29 | 5.1% |
| Ultra Moving Average Rating Trend Strategy by exlux99 | ema wma highest lowest sma rma vwma hma | v5 strategy | +2.8% | 5 | 2.4% |
| VCP pivot buy by perrycc007 | sma ema rma vwma wma lowest highest | v4 strategy | does not run in Zeal Terminal | ||
| MACD Willy Strategy by PtGambler | rma sma ema highest lowest wma | v5 strategy | No trades on this market | ||
| Multi Trend Cross Strategy Template by TradeAutomation | ema hma rma sma vwma wma highest lowest | v5 strategy | +33.0% | 3 | 7.3% |
| Multi MA Trend Following Strategy Template by TradeAutomation | ema hma rma sma vwma wma highest lowest | v5 strategy | +12.3% | 3 | 26.9% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 36 ms | With a workaround 1,000 bars in 114 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © HeWhoMustNotBeNamed//@version=4strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)BBLength = input(100, minval=1, step=1)StdDev = 10useMovingAverage = input(true)MAType = input(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])lookbackPeriod = input(22, minval=10, step=10)colorByPreviousClose = input(true)delaySignalBars = input(2, minval=2)AtrMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])AtrLength = input(10)AtrMult = input(4)wicks = input(false)considerYearlyHighLow = input(false)considerNewLongTermHighLows = input(false)shortHighLowPeriod = 100longHighLowPeriod = 200tradeDirection = input(title="Trade Direction", defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])backtestYears = input(10, minval=1, step=1)//////////////////////////////////// Calculate new high low condition //////////////////////////////////////////////////f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)=> newHigh = highest(shortHighLowPeriod) == highest(longHighLowPeriod) or not considerNewLongTermHighLows newLow = lowest(shortHighLowPeriod) == lowest(longHighLowPeriod) or not considerNewLongTermHighLows [newHigh,newLow]//////////////////////////////////// Calculate Yearly High Low //////////////////////////////////////////////////f_getYearlyHighLowCondition(considerYearlyHighLow)=> yhigh = security(syminfo.tickerid, '12M', high[1]) ylow = security(syminfo.tickerid, '12M', low[1]) yhighlast = yhigh[365] ylowlast = ylow[365] yhighllast = yhigh[2 * 365] ylowllast = ylow[2 * 365] yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > max(yhigh,yhighlast) : close > max(yhigh, min(yhighlast, yhighllast)) yearlyHighCondition = ( (na(yhigh) or na(yhighlast) ? true : (yhigh > yhighlast) ) and ( na(yhigh) or na(yhighllast) ? true : (yhigh > yhighllast))) or yearlyTrendUp or not considerYearlyHighLow yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < min(ylow,ylowlast) : close < min(ylow, max(ylowlast, ylowllast)) yearlyLowCondition = ( (na(ylow) or na(ylowlast) ? true : (ylow < ylowlast) ) and ( na(ylow) or na(ylowllast) ? true : (ylow < ylowllast))) or yearlyTrendDown or not considerYearlyHighLow label_x = time+(60*60*24*1000*1) [yearlyHighCondition,yearlyLowCondition]f_getMovingAverage(source, MAType, length)=> ma = sma(source, length) if(MAType == "ema") ma := ema(source,length) if(MAType == "hma") ma := hma(source,length) if(MAType == "rma") ma := rma(source,length) if(MAType == "vwma") ma := vwma(source,length) if(MAType == "wma") ma := wma(source,length) mainDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)[yearlyHighCondition,yearlyLowCondition] = f_getYearlyHighLowCondition(considerYearlyHighLow)[newHighS,newLowS] = f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)[middleclose, upperclose, lowerclose] = bb(close, BBLength, StdDev)[middleopen, upperopen, loweropen] = bb(open, BBLength, StdDev)[middlehigh, upperhigh, lowerhigh] = bb(high, BBLength, StdDev)[middlelow, upperlow, lowerlow] = bb(low, BBLength, StdDev)percentBClose = (close - lowerclose)*100/(upperclose-lowerclose)percentBOpen = (open - loweropen)*100/(upperopen-loweropen)percentBHigh = (high - lowerhigh)*100/(upperhigh-lowerhigh)percentBLow = (low - lowerlow)*100/(upperlow-lowerlow)percentBMAClose = f_getMovingAverage(percentBClose, MAType, lookbackPeriod)percentBMAOpen = f_getMovingAverage(percentBOpen, MAType, lookbackPeriod)percentBMAHigh = f_getMovingAverage(percentBHigh, MAType, lookbackPeriod)percentBMALow = f_getMovingAverage(percentBLow, MAType, lookbackPeriod)newOpen = useMovingAverage? percentBMAOpen : percentBOpennewClose = useMovingAverage? percentBMAClose : percentBClosenewHigh = useMovingAverage? percentBMAHigh : percentBHighnewLow = useMovingAverage? percentBMALow : percentBLowtruerange = max(newHigh, newClose[1]) - min(newLow, newClose[1])averagetruerange = f_getMovingAverage(truerange, AtrMAType, AtrLength)atr = averagetruerange * AtrMultlongStop = newClose - atrlongStopPrev = nz(longStop[1], longStop)longStop := (wicks ? newLow[1] : newClose[1]) > longStopPrev ? max(longStop, longStopPrev) : longStopshortStop = newClose + atrshortStopPrev = nz(shortStop[1], shortStop)shortStop := (wicks ? newHigh[1] : newClose[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStopdir = 1dir := nz(dir[1], dir)dir := dir == -1 and (wicks ? newHigh : newClose) > shortStopPrev ? 1 : dir == 1 and (wicks ? newLow : newClose) < longStopPrev ? -1 : dirtrailingStop = dir == 1? longStop : shortStopcandleColor = colorByPreviousClose ? (newClose[1] < newClose ? color.green : newClose[1] > newClose ? color.red : color.silver) : (newOpen < newClose ? color.green : newOpen > newClose ? color.red : color.silver)plotcandle(newOpen, newHigh, newLow, newClose, title='PercentBCandle', color = candleColor)plot(trailingStop, title="TrailingStop", style=plot.style_linebr, linewidth=1, color= dir == 1 ? color.green : color.red)buyCondition = lowest(dir,delaySignalBars)==1 and yearlyHighCondition and newHighSexitBuyCondition = highest(dir,delaySignalBars) == -1sellCondition = highest(dir,delaySignalBars) == -1 and yearlyLowCondition and newLowSexitSellCondition = lowest(dir,delaySignalBars) == 1strategy.risk.allow_entry_in(tradeDirection)barcolor(buyCondition? color.lime : sellCondition ? color.orange : color.silver)strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.none)strategy.close("Buy", when=exitBuyCondition)strategy.entry("Sell", strategy.short, when=sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.none)strategy.close("Sell", when=exitSellCondition)