Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Steven Primo's bollinger bands strategy

A Pine Script v5 strategy built on BB (close, 20), Pivothigh (1, 1) and Pivotlow (1, 1). It has 8 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 100% of equity and pays no commission. 7 settings; defaults include Price source close, Bollinger length 20 and Standard deviation 0.382.

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 Steven Primo's bollinger bands 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 Steven Primo's bollinger bands strategy do on BTCUSDT 1D with default settings?
−17.74%
From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Steven Primo's bollinger bands strategy 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: 15 before, 11 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Steven Primo's bollinger bands strategy use a stop loss?
Yes
strategy.exit sets a stop on line 97, 98, 105, 108.
Does Steven Primo's bollinger bands strategy run in Zeal Terminal?
Yes
It compiles in 67 ms and runs 1,000 bars in 87 ms, in the browser.

BTCUSDT · 1D · default settings

  • Middle band
  • Upper band
  • Lower band
  • Stop loss
  • Target
  • 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 (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$876,416$2,025,273Equity from $1,000,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
−17.74%
−$177,400.00
Buy and hold
+102.5%
same period
Closed trades
15
7 won · 8 lost
Profitable
46.7%
of closed trades
Profit factor
0.69
gross profit ÷ gross loss
Max drawdown
28.24%
−$282,418.00

One run with the author's default settings, $1,000,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

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 105, 108. The upgraded version below moves each call inside an if block.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Bollinger settings
Price sourceclosesourcemiddle upper lower
Bollinger length20int · min 3middle upper lower
Standard deviation0.382float · min 0.0 · step 0.1middle upper lower
Setup settings
Order directionLONGstring · options [LONG, SHORT, ALL]line 82
Use trailing stopfalseboolline 103
Consecutive closes for the setup5int · min 1canBuy canSell
Extension (%)100int · min 100totalTicks

What it calculates

  • BBPrice source (close), Bollinger length (20), Standard deviation (0.382)middle · line 21
  • BBPrice source (close), Bollinger length (20), Standard deviation (0.382)upper · line 21
  • BBPrice source (close), Bollinger length (20), Standard deviation (0.382)lower · line 21
  • Pivothigh1, 1pivotHigh · line 48
  • Pivotlow1, 1pivotLow · line 49

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 databollingerLengthBollinger lengthsetting · 20multStandard deviationsetting · 0.382extensionExtension (%)setting · 100highhighprice dataconsecutiveClosesConsecutive closes for …setting · 5lowlowprice datamiddleBB→ middleupperBB→ upperlowerBB→ lowerpivotHighPivothigh→ pivotHighpivotLowPivotlow→ pivotLowLONG, SHORT, ALLLONG · SHORT +13 valuescountLongcountLongvaluecountShortcountShortvaluepvHighInRangepvHighInRangevaluepvLowInRangepvLowInRangevalueepLongepLongvalueepShortepShortvaluestopLongstopLongvaluestopShortstopShortvaluetotalTickstotalTicksvaluetargetLongtargetLongvaluetargetShorttargetShortvalueplotTargetplotTargetvalueplotStopplotStopvaluecanBuycanBuyconditioncanSellcanSellconditioninMarketinMarketconditioncolorAtTheLimits, colorAtTheMiddleColourcolorAtTheLimits · colorAtThe…entry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entrycancel:longcancel longstrategy.cancelcancel:shortcancel shortstrategy.cancelexit:longexit longstrategy.exitexit:shortexit shortstrategy.exitplot:28Middle bandplotplot:29Upper bandplotplot:30Lower bandplotplot:112Stop lossplotplot:113Targetplot

Order rules

OrderFires whenBy defaultLine
Open long longcanBuyOn87
Open short shortcanSellOn91
cancel longcanSellOn93
cancel shortcanSellOn94
Exit long stop and limitnot inMarketOn97
Exit short stop and limitnot inMarketOn98
Exit long stop and limitstopLong > plotStopOn105
Exit short stop and limitstopShort < plotStopOn108

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.

4/4trades 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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−17.7%+102.5%1547%0.6928.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−3.3%+5.5%1338%0.799.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−15.3%+9.8%1443%0.6934.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−24.2%+8.4%1315%0.1624.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−8.0%+16.7%1338%0.9131.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−26.4%+21.5%1429%0.2727.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−33.8%+148.3%2138%0.5442.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+17.2%+17.1%1656%2.318.5%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 market633%−$166,598.00
Sideways market633%−$96,191.10
Falling market3100%$85,388.70

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

42.1%

The 95th percentile of the worst drawdown when the same 15 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 23.0% to 42.1%; the tick is what actually happened, 23.8%. Order luck alone moves it this much.

0%48%
All 15 trades
SideEntryExitBarsP&L
long20 Feb 2024 52,816.6023 Feb 2024 50,625.003−$41,495.30
long27 May 2024 69,610.0011 Jun 2024 66,312.1015−$45,410.30
long19 Jul 2024 66,128.605 Aug 2024 56,542.5017−$132,365.00
long23 Sep 2024 64,133.3029 Oct 2024 70,773.4036$80,832.80
long10 Nov 2024 77,200.0011 Nov 2024 87,565.001$115,675.00
long4 Dec 2024 98,130.005 Dec 2024 90,791.101−$73,085.40
long19 Jan 2025 105,865.0025 Feb 2025 89,256.7037−$141,847.00
long21 Apr 2025 85,678.0021 Apr 2025 88,244.400$22,833.80
long25 Apr 2025 94,696.1012 May 2025 105,443.0017$89,101.20
long9 Jul 2025 109,700.0010 Jul 2025 112,155.001$19,565.00
long15 Sep 2025 116,666.0025 Sep 2025 109,977.0010−$51,243.50
long12 Jan 2026 92,082.6013 Jan 2026 94,854.101$25,360.10
long16 Mar 2026 73,913.8019 Mar 2026 70,317.003−$42,234.50
long13 Apr 2026 73,790.0017 Apr 2026 77,114.004$37,194.80
long20 Jul 2026 65,600.0031 Jul 2026 62,537.6011−$40,282.70

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
Steven Primo's bollinger bands strategy this page—v5 strategy−17.7%1528.2%
Pivot Point Breakout by EduardoMattjepivotlow pivothighv5 strategy+93.0%2532.3%
Monthly Returns of a Strategy in a Chart by QuantNomadpivothigh pivotlowv5 strategy+21.0%7613.0%
ZigZag by Zeal Terminalpivothigh pivotlowv5 indicatorindicator
RSI Centered Pivots by OztheWozpivotlow pivothighv4 strategy+98.0%4160.2%
ABCD Strategy by kerok3gpivothigh pivotlowv5 strategy−2.7%43.0%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 2 strategy calls use the when = argument (line 105, 108). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 15 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 105: when = stopLong > plotStop → if block
  • Line 108: when = stopShort < plotStop → if block
⋯    if strategy.position_entry_name == "long"-        strategy.exit("long", "long", stop=stopLong, limit=plotTarget, comment="Exit long", when=stopLong > plotStop)+        if stopLong > plotStop+            strategy.exit("long", "long", stop=stopLong, limit=plotTarget, comment="Exit long")        plotStop := stopLong    else-        strategy.exit("short", "short", stop=stopShort, limit=plotTarget, comment="Exit short", when=stopShort < plotStop) +        if stopShort < plotStop+            strategy.exit("short", "short", stop=stopShort, limit=plotTarget, comment="Exit short")         plotStop := stopShort⋯

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: 15 before, 11 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.

⋯// © EduardoMattje-//@version=5+//@version=6strategy("Steven Primo Bollinger Band", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, process_orders_on_close=true, max_labels_count=500)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 67 msYes 1,000 bars in 87 msNot measured
PineTSNot testedNot testedNot 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.

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/// © EduardoMattje//@version=5strategy("Steven Primo Bollinger Band", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, process_orders_on_close=true, max_labels_count=500)// Constantsvar TRANSP = 5var LONG = strategy.direction.longvar SHORT = strategy.direction.shortvar ALL = strategy.direction.allvar S_BOLLINGER = "Bollinger settings"var S_SETUP = "Setup settings"// Inputssrc = math.log(input.source(close, "Price source", group=S_BOLLINGER))var bollingerLength = input.int(20, "Bollinger length", minval=3, group=S_BOLLINGER, inline=S_BOLLINGER)var mult = input.float(0.382, "Standard deviation", minval=0.0, step=0.1, group=S_BOLLINGER, inline=S_BOLLINGER)var orderDirection = input.string(LONG, "Order direction", options=[LONG, SHORT, ALL], group=S_SETUP)var useTrailingStop = input.bool(false, "Use trailing stop", group=S_SETUP)var consecutiveCloses = input.int(5, "Consecutive closes for the setup", minval=1, group=S_SETUP, inline=S_SETUP)var extension = input.int(100, "Extension (%)", minval=100, group=S_SETUP, inline=S_SETUP) / 100.0// Getting the BB[middle, upper, lower] = ta.bb(src, bollingerLength, mult)middle := math.exp(middle)upper := math.exp(upper)lower := math.exp(lower)// Plotting the BBvar colorAtTheLimits = color.new(color.yellow, TRANSP)var colorAtTheMiddle = color.new(color.blue, TRANSP)plot(middle, "Middle band", colorAtTheMiddle, display=display.none)plot(upper, "Upper band", colorAtTheLimits)plot(lower, "Lower band", colorAtTheLimits)// MA setup// BB setuplongComparison() => close >= uppershortComparison() => close <= lowervar countLong = 0var countShort = 0incCount(count, comparison) =>    if comparison        if count == 0 and comparison[1]            0        else            count + 1    else        0countLong := incCount(countLong, longComparison())countShort := incCount(countShort, shortComparison())// Pivot setuppivotHigh = ta.pivothigh(1, 1)pivotLow = ta.pivotlow(1, 1)pivotInRange(pivot, count) => ta.barssince(pivot) < countpvHighInRange = pivotInRange(pivotHigh, countLong)pvLowInRange = pivotInRange(pivotLow, countShort)// Entry priceepLong = fixnan(pivotHigh) + syminfo.mintickepShort = fixnan(pivotLow) - syminfo.mintick// Stop pricegetRange(currentPrice, pivot, cond, tickMod) =>    if cond        currentPrice    else        fixnan(pivot) + syminfo.mintick * tickModvar stopLong = 0.0var stopShort = 0.0stopLong := epShortstopShort := epLong        // Target pricegetTarget(stopPrice, entryPrice) =>    totalTicks = (entryPrice - stopPrice) * extension    entryPrice + totalTicksvar targetLong = 0.0var targetShort = 0.0targetLong := getTarget(stopLong, epLong)targetShort := getTarget(stopShort, epShort)// Entry conditioncanBuy = countLong >= consecutiveCloses and pvHighInRange and high < epLongcanSell = countShort >= consecutiveCloses and pvLowInRange and low > epShort// Entry ordersinMarket = strategy.opentrades != 0var plotTarget = 0.0var plotStop = 0.0strategy.risk.allow_entry_in(orderDirection)if not inMarket    if canBuy        plotTarget := targetLong        plotStop := stopLong        strategy.entry("long", strategy.long, stop=epLong, comment="Entry long")    else if canSell        plotTarget := targetShort        plotStop := stopShort        strategy.entry("short", strategy.short, stop=epShort, comment="Entry short")    else        strategy.cancel("long")        strategy.cancel("short")            // Exit orders    strategy.exit("long", "long", stop=stopLong, limit=targetLong, comment="Exit long")    strategy.exit("short", "short", stop=stopShort, limit=targetShort, comment="Exit short")else    countLong := 0    countShort := 0// Trailing stopif useTrailingStop and inMarket    if strategy.position_entry_name == "long"        strategy.exit("long", "long", stop=stopLong, limit=plotTarget, comment="Exit long", when=stopLong > plotStop)        plotStop := stopLong    else        strategy.exit("short", "short", stop=stopShort, limit=plotTarget, comment="Exit short", when=stopShort < plotStop)         plotStop := stopShort// Plot exitplotCond(price) => inMarket ? price : inMarket[1] ? price[1] : naplot(plotCond(plotStop), "Stop loss", color.red, style=plot.style_linebr)plot(plotCond(plotTarget), "Target", color.teal, style=plot.style_linebr)