Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Bollinger Bands Strategy with Intraday Intensity Index

A Pine Script v4 strategy built on SMA or EMA (src_, len_) and Barssince (buy). It has 8 order rules, 4 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. 9 settings; defaults include Bollinger Bands length 20, Bollinger Bands and Standard deviation type EMA and source close.

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 Bands Strategy with Intraday Intensity Index 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 Bollinger Bands Strategy with Intraday Intensity Index do on BTCUSDT 1D with default settings?
−0.23%
From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Bollinger Bands Strategy with Intraday Intensity Index 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 Bands Strategy with Intraday Intensity Index use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Bollinger Bands Strategy with Intraday Intensity Index run in Zeal Terminal?
Yes
It compiles in 18 ms and runs 1,000 bars in 89 ms, in the browser.

BTCUSDT · 1D · default settings

  • Bollinger Bands Upper Line
  • Bollinger Bands Lower Line
  • Bollinger Bands Mid line
  • 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 (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$99,766$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. Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 58, 61, 64, 66) so the engine trades the way the script says.
Net profit
−0.23%
−$234.98
Buy and hold
+102.5%
same period
Closed trades
25
18 won · 7 lost
Profitable
72.0%
of closed trades
Profit factor
1.00
gross profit ÷ gross loss
Max drawdown
30.64%
−$32,986.40

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. 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.

  • Check

    No commission

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

  • Note

    2 settings have no label

    In the settings dialog positionMode (line 15), earlyExit (line 16) 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 58, 59, 61, 62, 64, 65, 66, 67. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 58

    long = on line 58, 61, 64, 66. v5 writes it as direction = strategy.long or strategy.short.

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 sma → ta.sma, ema → ta.ema, sum → math.sum, pow → math.pow, sqrt → math.sqrt, barssince → ta.barssince.
  • 8 strategy calls use the when = argument (line 58, 59, 61, 62, 64, 65, 66, 67). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 1: //@version=4 → //@version=5
  • Line 9: input(type = input.string) → input.string()
  • Line 21: sma → ta.sma
  • Line 23: ema → ta.ema
  • Line 29: sum → math.sum
  • Line 39: pow → math.pow
7 more edits
  • Line 41: sqrt → math.sqrt
  • Line 54: barssince → ta.barssince
  • Line 56: barssince → ta.barssince
  • Line 58: long = true → direction = strategy.long
  • Line 61: long = false → direction = strategy.short
  • Line 64: long = true → direction = strategy.long
  • Line 66: long = false → direction = strategy.short
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯BBlength = input(20, title="Bollinger Bands length")-BBtype = input("EMA", title="Bollinger Bands and Standard deviation type", type=input.string, options=["EMA", "SMA"])+BBtype = input.string("EMA", title="Bollinger Bands and Standard deviation type", options=["EMA", "SMA"])BBprice = input(close, title="source")⋯    if type_ == "SMA"-        result := sma(src_, len_)+        result := ta.sma(src_, len_)    if type_ == "EMA"-        result := ema(src_, len_)+        result := ta.ema(src_, len_)    result⋯i = k1 / k2-iSum = sum(i, IIIlength)+iSum = math.sum(i, IIIlength)//standard deviation with exponential option⋯        for counter = 0 to len_ - 1-            sumSqr := sumSqr + pow( src_[counter] - mean, 2 )+            sumSqr := sumSqr + math.pow( src_[counter] - mean, 2 )        variance := sumSqr / len_-        stdDev = sqrt( variance )+        stdDev = math.sqrt( variance )    else⋯buy = close[1]<BBlower[1] and close>BBlower and (withIII ? iSum>0 : 1)-sell = close>BBbasis or (earlyExit?strategy.openprofit>0:0) or barssince(buy)>timeStop+sell = close>BBbasis or (earlyExit?strategy.openprofit>0:0) or ta.barssince(buy)>timeStopshort = close[1]>BBupper[1] and close<BBupper and (withIII ? iSum<0 : 1)-cover = close<BBbasis or (earlyExit?strategy.openprofit>0:0) or barssince(short)>timeStop+cover = close<BBbasis or (earlyExit?strategy.openprofit>0:0) or ta.barssince(short)>timeStopif positionMode=="Long only"-    strategy.entry(id="enter long", long=true, when=buy)+    strategy.entry(id="enter long", direction = strategy.long, when=buy)    strategy.close(id="enter long", comment="exit long", when=sell)else if positionMode=="Short only"-    strategy.entry(id="enter short", long=false, when=short)+    strategy.entry(id="enter short", direction = strategy.short, when=short)    strategy.close(id="enter short", comment="exit short", when=cover)else-    strategy.entry(id="enter long", long=true, when=buy)+    strategy.entry(id="enter long", direction = strategy.long, when=buy)    strategy.close(id="enter long", comment="exit long", when=sell)-    strategy.entry(id="enter short", long=false, when=short)+    strategy.entry(id="enter short", direction = strategy.short, when=short)    strategy.close(id="enter short", comment="exit short", when=cover)

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.int()
  • Line 10: input() → input.source()
  • Line 11: input() → input.int()
  • Line 12: input() → input.float()
  • Line 13: input() → input.bool()
  • Line 14: input() → input.int()
10 more edits
  • Line 15: input() → input.string()
  • Line 16: input() → input.bool()
  • Line 58: when = buy → if block
  • Line 59: when = sell → if block
  • Line 61: when = short → if block
  • Line 62: when = cover → if block
  • Line 64: when = buy → if block
  • Line 65: when = sell → if block
  • Line 66: when = short → if block
  • Line 67: when = cover → if block
⋯strategy(title="Bollinger Bands Strategy with Intraday Intensity Index", shorttitle="Bollinger Bands Strategy", overlay=true)-BBlength = input(20, title="Bollinger Bands length")+BBlength = input.int(20, title="Bollinger Bands length")BBtype = input.string("EMA", title="Bollinger Bands and Standard deviation type", options=["EMA", "SMA"])-BBprice = input(close, title="source")+BBprice = input.source(close, title="source")-timeStop = input(20, title="Time-based stop length")+timeStop = input.int(20, title="Time-based stop length")-BBmult = input(2.0, title="Bollinger Bands Standard Deviation")+BBmult = input.float(2.0, title="Bollinger Bands Standard Deviation")-withIII = input(false, title="with Intraday Intensity Index?")+withIII = input.bool(false, title="with Intraday Intensity Index?")-IIIlength = input(21, title="Intraday Intensity Index length")+IIIlength = input.int(21, title="Intraday Intensity Index length")-positionMode = input("Both long and short", options=["Both long and short", "Long only", "Short only"])+positionMode = input.string("Both long and short", options=["Both long and short", "Long only", "Short only"])-earlyExit = input(false)+earlyExit = input.bool(false)//function for choosing moving averages⋯if positionMode=="Long only"-    strategy.entry(id="enter long", direction = strategy.long, when=buy)+    if buy+        strategy.entry(id="enter long", direction = strategy.long)-    strategy.close(id="enter long", comment="exit long", when=sell)+    if sell+        strategy.close(id="enter long", comment="exit long")else if positionMode=="Short only"-    strategy.entry(id="enter short", direction = strategy.short, when=short)+    if short+        strategy.entry(id="enter short", direction = strategy.short)-    strategy.close(id="enter short", comment="exit short", when=cover)+    if cover+        strategy.close(id="enter short", comment="exit short")else-    strategy.entry(id="enter long", direction = strategy.long, when=buy)+    if buy+        strategy.entry(id="enter long", direction = strategy.long)-    strategy.close(id="enter long", comment="exit long", when=sell)+    if sell+        strategy.close(id="enter long", comment="exit long")-    strategy.entry(id="enter short", direction = strategy.short, when=short)+    if short+        strategy.entry(id="enter short", direction = strategy.short)-    strategy.close(id="enter short", comment="exit short", when=cover)+    if cover+        strategy.close(id="enter short", comment="exit short")

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: 25 before, 26 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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

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

SettingDefaultType and rangeFeeds
Bollinger Bands length20intBBdev BBbasis
Bollinger Bands and Standard deviation typeEMAstring · options ["EMA", "SMA"]BBdev BBbasis
sourceclosesourceBBdev BBbasis
Time-based stop length20intsell cover
Bollinger Bands Standard Deviation2.0floatBBdev
with Intraday Intensity Index?falseboolbuy short
Intraday Intensity Index length21intiSum
Position Mode (no label in the script)Both long and shortstring · options ["Both long and short", "Long only", "Short only"]entry enter long close enter long entry enter short close enter short entry enter long close enter long entry enter short close enter short line 57 line 60
Early Exit (no label in the script)falseboolsell cover

What it calculates

  • SMA / EMA (sma, ta.sma in v5)src_, len_result · line 21
  • Barssince (barssince, ta.barssince in v5)buysell · line 54
  • Barssince (barssince, ta.barssince in v5)shortcover · line 56

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 datatimeStopTime-based stop lengthsetting · 20volumevolumeprice datalowlowprice datahighhighprice dataIIIlengthIntraday Intensity Inde…setting · 21BBmultBollinger Bands Standar…setting · 2.0BBtypeBollinger Bands and Sta…setting · EMABBlengthBollinger Bands lengthsetting · 20resultSMA / EMA→ resultsellBarssince→ sellcoverBarssince→ coverk1k1valuek2k2valueiivalueiSumiSumvaluemeanmeanvaluesumSqrsumSqrvaluevariancevariancevalueBBdevBBdevvalueBBbasisBBbasisvalueBBupper, BBlowerBBupper · BBlower2 valuesbuybuyvalueshortshortvalueentry:enter longOpen enter longstrategy.entryclose:enter longClose enter longstrategy.closeentry:enter shortOpen enter shortstrategy.entryclose:enter shortClose enter shortstrategy.closeplot:49Bollinger Bands Upper L…plotplot:50Bollinger Bands Lower L…plotplot:51Bollinger Bands Mid lineplot

Order rules

OrderFires whenBy defaultLine
Open enter long longbuyOn58
Close enter longsellOn59
Open enter short shortshortOn61
Close enter shortcoverOn62
Open enter long longbuyOn64
Close enter longsellOn65
Open enter short shortshortOn66
Close enter shortcoverOn67

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−0.2%+102.5%2572%1.0030.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−4.1%+5.5%3184%0.8516.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.1%+9.8%2552%0.631.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.6%+8.4%2759%0.511.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%2763%1.340.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%2763%0.580.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.1%+148.3%2357%0.770.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%2882%1.450.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 barsTradesWonP&L
Rising market1060%−$23,453.40
Sideways market978%$10,223.40
Falling market683%$12,995.10

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

How bad could the drawdown be?

38.6%

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

0%44%
All 25 trades
SideEntryExitBarsP&L
short16 Feb 2024 51,880.0020 Mar 2024 61,937.4033−$10,057.40
long15 Apr 2024 65,661.9023 Apr 2024 66,819.308$1,157.47
long4 May 2024 62,882.005 May 2024 63,892.001$1,010.02
short22 May 2024 70,148.3012 Jun 2024 67,314.2021$2,834.11
long7 Jul 2024 58,230.1015 Jul 2024 60,797.908$2,567.78
long7 Aug 2024 56,022.009 Aug 2024 61,686.002$5,664.00
short31 Oct 2024 72,344.805 Nov 2024 67,850.005$4,494.74
short10 Nov 2024 76,677.505 Dec 2024 98,587.3025−$21,909.90
short10 Dec 2024 97,276.5020 Dec 2024 97,461.9010−$185.38
short19 Jan 2025 104,556.0029 Jan 2025 101,336.0010$3,220.71
long1 Mar 2025 84,349.903 Mar 2025 94,270.002$9,920.04
long8 Apr 2025 79,163.2012 Apr 2025 83,423.804$4,260.59
short24 Apr 2025 93,691.1031 May 2025 103,985.0037−$10,294.40
short13 Jul 2025 117,420.001 Aug 2025 115,764.0019$1,655.93
short15 Aug 2025 118,295.0016 Aug 2025 117,342.001$953.05
short5 Oct 2025 122,391.0011 Oct 2025 112,774.006$9,616.50
long6 Nov 2025 103,885.0029 Nov 2025 90,890.7023−$12,994.40
long17 Dec 2025 87,863.4031 Dec 2025 88,485.5014$622.07
short7 Jan 2026 93,748.0021 Jan 2026 88,427.7014$5,320.31
long7 Feb 2026 70,580.303 Mar 2026 68,830.1024−$1,750.20
short8 May 2026 80,006.0016 May 2026 79,113.208$892.80
long7 Jun 2026 60,884.604 Jul 2026 62,583.3027$1,698.64
short23 Jul 2026 66,114.5025 Jul 2026 64,140.002$1,974.50
short24 Aug 2026 77,734.0011 Sep 2026 76,568.7018$1,165.27
short20 Sep 2026 81,250.008 Oct 2026 83,321.8018−$2,071.82

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
Bollinger Bands Strategy with Intraday Intensity Index this page—v4 strategy−0.2%2530.6%
Dazzling Bolts by OrcChieftainsma ema barssincev4 strategy+8.5%1413.0%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
Last Price minus Open Price Intraday Volume by avsr90barssince smav5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msWith a workaround 1,000 bars in 89 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 58, 61, 64, 66) so the engine trades the way the script says.

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

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// Bollinger Bands Strategy with Intraday Intensity Index// by SparkyFlary//For Educational Purposes//Results can differ on different markets and can fail at any time. Profit is not guaranteed.strategy(title="Bollinger Bands Strategy with Intraday Intensity Index", shorttitle="Bollinger Bands Strategy", overlay=true)BBlength = input(20, title="Bollinger Bands length")BBtype = input("EMA", title="Bollinger Bands and Standard deviation type", type=input.string, options=["EMA", "SMA"])BBprice = input(close, title="source")timeStop = input(20, title="Time-based stop length")BBmult = input(2.0, title="Bollinger Bands Standard Deviation")withIII = input(false, title="with Intraday Intensity Index?")IIIlength = input(21, title="Intraday Intensity Index length")positionMode = input("Both long and short", options=["Both long and short", "Long only", "Short only"])earlyExit = input(false)//function for choosing moving averagesf_ma(type_, src_, len_) =>    float result = 0    if type_ == "SMA"        result := sma(src_, len_)    if type_ == "EMA"        result := ema(src_, len_)    result//Intraday Intensity Indexk1 = (2 * close - high - low) * volumek2 = high != low ? high - low : 1i = k1 / k2iSum = sum(i, IIIlength)//standard deviation with exponential optionStdDev_(type_, src_, len_) =>    mean = 0.0    sumSqr = 0.0    variance = 0.0    if len_ > 0        mean := f_ma( type_, src_, len_ )        sumSqr := 0        for counter = 0 to len_ - 1            sumSqr := sumSqr + pow( src_[counter] - mean, 2 )        variance := sumSqr / len_        stdDev = sqrt( variance )    else        stdDev = -1//Bollinger BandsBBdev = BBmult * StdDev_(BBtype, BBprice, BBlength)BBbasis = f_ma(BBtype, BBprice, BBlength)BBupper = BBbasis + BBdevBBlower = BBbasis - BBdevplot(BBupper, title="Bollinger Bands Upper Line")plot(BBlower, title="Bollinger Bands Lower Line")plot(BBbasis, title="Bollinger Bands Mid line", color=color.maroon)//Strategybuy = close[1]<BBlower[1] and close>BBlower and (withIII ? iSum>0 : 1)sell = close>BBbasis or (earlyExit?strategy.openprofit>0:0) or barssince(buy)>timeStopshort = close[1]>BBupper[1] and close<BBupper and (withIII ? iSum<0 : 1)cover = close<BBbasis or (earlyExit?strategy.openprofit>0:0) or barssince(short)>timeStopif positionMode=="Long only"    strategy.entry(id="enter long", long=true, when=buy)    strategy.close(id="enter long", comment="exit long", when=sell)else if positionMode=="Short only"    strategy.entry(id="enter short", long=false, when=short)    strategy.close(id="enter short", comment="exit short", when=cover)else    strategy.entry(id="enter long", long=true, when=buy)    strategy.close(id="enter long", comment="exit long", when=sell)    strategy.entry(id="enter short", long=false, when=short)    strategy.close(id="enter short", comment="exit short", when=cover)