Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

BBPullback1.0.2

A Pine Script v5 strategy built on SMA (source, length) and Stdev (source, length). It has 12 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 3 settings; defaults include Take Proft trigger OPTION0.

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 BBPullback1.0.2 repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did BBPullback1.0.2 do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Does BBPullback1.0.2 run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
Does BBPullback1.0.2 use a stop loss?
Yes
strategy.exit sets a stop on line 173, 202.
Does BBPullback1.0.2 run in Zeal Terminal?
Yes
It compiles in 78 ms and runs 1,000 bars in 98 ms, in the browser.

BTCUSDT · 1D · default settings

  • TheMin
  • TheMax
  • UpperBB
  • LowerBB
  • SwingLow
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,000,000$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
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

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

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

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

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

SettingDefaultType and rangeFeeds
Take Proft triggerOPTION0string · options [OPTION0,OPTION1,OPTION2]line 15 line 17
Fromtimestamp("23 Feb 2023 00:00 +0000")timeline 72
Thrutimestamp("09 Apr 2023 00:00 +0000")timeline 72

What it calculates

  • SMAsource, lengthbasis · line 27
  • Stdevsource, lengthdev · line 28

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 dataopenopenprice databasisSMA→ basisdevStdev→ devtake_profit_option, state, buy_entry_price, sell_entry_price, buy_stoploss_price, sell_stoploss_price, swing_lowtake_profit_option · st…7 valuessourcesourcevalueupperBBValue, lowerBBValueupperBBValue · lowerBBV…2 valuesthemax, theminthemax · themin2 valuescancel:Enter Longcancel Enter Longstrategy.cancelcancel:Enter Shortcancel Enter Shortstrategy.cancelentry:Enter LongOpen Enter Longstrategy.entryexit:Stop Outexit Stop Outstrategy.exitentry:Enter ShortOpen Enter Shortstrategy.entryclose:Enter LongClose Enter Longstrategy.closeclose:Enter ShortClose Enter Shortstrategy.closeplotchar:230plotcharplotcharplotchar:231plotcharplotcharplotchar:232plotcharplotcharplotchar:233plotcharplotcharplotchar:234plotcharplotcharplotchar:235plotcharplotcharplotchar:236plotcharplotcharplotchar:238plotcharplotchar

Order rules

OrderFires whenBy defaultLine
cancel Enter Long(array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG)On149
cancel Enter Short(array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT)On153
Open Enter Long long(LongTriggerCondition())On171
Exit Stop Out stop(LongTriggerCondition())On173
Open Enter Long long(PullbackCandleLong())On178
cancel Enter Long(array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG)On181
Open Enter Short short(ShortTriggerCondition())On200
Exit Stop Out stop(ShortTriggerCondition())On202
Open Enter Short short(PullbackCandleShort())On208
cancel Enter Short(array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT)On211
Close Enter Long(LongTakeProfitHit())On217
Close Enter Short(ShortTakeProfitHit())On221

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

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
BBPullback1.0.2 this page—v5 strategy0.0%00.0%
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%

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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © westofpluto-//@version=5+//@version=6strategy("BBPullback", overlay=true, margin_long=100, margin_short=100,process_orders_on_close=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 78 msYes 1,000 bars in 98 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/// © westofpluto//@version=5strategy("BBPullback", overlay=true, margin_long=100, margin_short=100,process_orders_on_close=true)TAKE_PROFIT_HILO = 0TAKE_PROFIT_CLOSE = 1TAKE_PROFIT_BB = 2OPTION0 = "high crosses MA"OPTION1 = "closes beyond MA"OPTION2 = "high crosses opposite band"tpoption=input.string(OPTION0,title="Take Proft trigger",options=[OPTION0,OPTION1,OPTION2])i_from = input.time(defval = timestamp("23 Feb 2023 00:00 +0000"), title = "From")i_thru = input.time(defval = timestamp("09 Apr 2023 00:00 +0000"), title = "Thru")var take_profit_option=TAKE_PROFIT_HILOif tpoption == OPTION0    take_profit_option := TAKE_PROFIT_HILOelse if tpoption == OPTION1    take_profit_option := TAKE_PROFIT_CLOSEelse    take_profit_option := TAKE_PROFIT_BB//// COMPUTE BOLLINGER BANDS INTERNALLY    //source = closelength = 20mult = 2.0basis = ta.sma(source, length)dev = mult * ta.stdev(source, length)upperBBValue = basis + devlowerBBValue = basis - devNO_SETUP = 0BB_BREAK_DOWN = 1RETRACE_BAR_UP = 2PENDING_ENTRY_LONG = 3ENTRY_LONG = 4BB_BREAK_UP = 5RETRACE_BAR_DOWN = 6PENDING_ENTRY_SHORT = 7ENTRY_SHORT = 8ID_STATE = 0ID_BUY_ENTRY = 0ID_SELL_ENTRY = 1ID_BUY_STOPLOSS = 2ID_SELL_STOPLOSS = 3ID_SWING_HIGH = 4ID_SWING_LOW = 5LARGE_NUMBER = 99999999.9var state = NO_SETUPvar buy_entry_price = 0.0var sell_entry_price = 0.0var buy_stoploss_price = 0.0var sell_stoploss_price = 0.0var swing_low = LARGE_NUMBERvar swing_high = 0.0var themax = 0.0var themin = 99999999.0//global_float = array.new_bool(1)//array.set(global_bool,ID_TRENDMODEON,trendMode)global_int = array.new_int(1)array.set(global_int,ID_STATE,state)global_float = array.new_float(6)array.set(global_float,ID_BUY_ENTRY,buy_entry_price)array.set(global_float,ID_SELL_ENTRY,sell_entry_price)array.set(global_float,ID_BUY_STOPLOSS,buy_stoploss_price)array.set(global_float,ID_SELL_STOPLOSS,sell_stoploss_price)array.set(global_float,ID_SWING_HIGH,swing_high)array.set(global_float,ID_SWING_LOW,swing_low)//// Main code starts here, executes every bar//dateok() =>     time >= i_from and time <= i_thru minval(x, y) =>    (x < y ? x : y)maxval(x, y) =>    (x > y ? x : y)IsFlat() =>    strategy.position_size == 0HasPosition() =>    strategy.position_size != 0PullbackCandleLong() =>    close >= open or low > low[1]PullbackCandleShort() =>    close <= open or high < high[1]isUpCandle() =>    close >= openisDownCandle() =>    open > closeStateInTrade() =>    array.get(global_int,ID_STATE) == ENTRY_LONG or array.get(global_int,ID_STATE) == ENTRY_SHORTStatePendingLong() =>    array.get(global_int,ID_STATE) == PENDING_ENTRY_LONGStatePendingShort() =>    array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORTStateInLongTrade() =>    array.get(global_int,ID_STATE) == ENTRY_LONGStateInShortTrade() =>    array.get(global_int,ID_STATE) == ENTRY_SHORTLongTakeProfitHigh() =>    high > basisShortTakeProfitLow() =>    low < basisLongTakeProfitClose() =>    close > basisShortTakeProfitClose() =>    close < basisLongTakeProfitBB() =>    high > upperBBValueShortTakeProfitBB() =>    low < lowerBBValueLongTakeProfitHit() =>    if take_profit_option == TAKE_PROFIT_HILO        LongTakeProfitHigh()    else if take_profit_option == TAKE_PROFIT_CLOSE        LongTakeProfitClose()    else        LongTakeProfitBB()ShortTakeProfitHit() =>    if take_profit_option == TAKE_PROFIT_HILO        ShortTakeProfitLow()    else if take_profit_option == TAKE_PROFIT_CLOSE        ShortTakeProfitClose()    else        ShortTakeProfitBB()LongTriggerCondition() =>    if (dateok() and isUpCandle() and minval(open,close) < lowerBBValue and high < basis and high > lowerBBValue)         true    else        falseShortTriggerCondition() =>    if (dateok() and isDownCandle() and maxval(open,close) > upperBBValue and low > basis and low < upperBBValue)         true    else        falseif (HasPosition() and StatePendingLong())    array.set(global_int,ID_STATE,ENTRY_LONG)else if (HasPosition() and StatePendingShort())    array.set(global_int,ID_STATE,ENTRY_SHORT)else if (IsFlat() and StateInTrade())     array.set(global_int,ID_STATE,NO_SETUP)//// If an order didn't trigger this bar then cancel it//var cancel_long=falsevar cancel_short=falseif IsFlat()    if (array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG)        cancel_long := true        strategy.cancel("Enter Long")        array.set(global_int,ID_STATE,NO_SETUP)    else if (array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT)        cancel_short := true        strategy.cancel("Enter Short")        array.set(global_int,ID_STATE,NO_SETUP)//// Trading logic long//if IsFlat()    if (array.get(global_int,ID_STATE) == NO_SETUP)         if (LongTriggerCondition())             //array.set(global_int,ID_STATE,BB_BREAK_DOWN)            array.set(global_float,ID_BUY_ENTRY,high)            if (cancel_long)                 array.set(global_float,ID_SWING_LOW,minval(low,array.get(global_float,ID_SWING_LOW)))            else                array.set(global_float,ID_SWING_LOW,low)                        array.set(global_float,ID_SWING_HIGH,0.0)            //array.set(global_float,ID_BUY_STOPLOSS,array.get(global_float,ID_SWING_LOW))            array.set(global_float,ID_BUY_STOPLOSS,low)            strategy.entry("Enter Long", strategy.long,stop=array.get(global_float,ID_BUY_ENTRY),limit=array.get(global_float,ID_BUY_ENTRY))            array.set(global_int,ID_STATE,PENDING_ENTRY_LONG)            strategy.exit("Stop Out",from_entry="Enter Long",stop=array.get(global_float,ID_BUY_STOPLOSS))    else if (array.get(global_int,ID_STATE) == BB_BREAK_DOWN)         if (PullbackCandleLong())            array.set(global_float,ID_BUY_ENTRY,high)            array.set(global_float,ID_BUY_STOPLOSS,low)            strategy.entry("Enter Long", strategy.long,stop=array.get(global_float,ID_BUY_ENTRY),limit=array.get(global_float,ID_BUY_ENTRY))            array.set(global_int,ID_STATE,PENDING_ENTRY_LONG)    else if (array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG)         strategy.cancel("Enter Long")        array.set(global_int,ID_STATE,NO_SETUP)//if (array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG) //    strategy.exit("Stop Out",from_entry="Enter Long",stop=array.get(global_float,ID_BUY_STOPLOSS))//// Trading logic short//if IsFlat()    if (array.get(global_int,ID_STATE) == NO_SETUP)         if (ShortTriggerCondition())            //array.set(global_int,ID_STATE,BB_BREAK_UP)            array.set(global_float,ID_SELL_ENTRY,low)            if (cancel_short)                 array.set(global_float,ID_SWING_HIGH,maxval(high,array.get(global_float,ID_SWING_HIGH)))            else                array.set(global_float,ID_SWING_HIGH,high)            array.set(global_float,ID_SWING_LOW,LARGE_NUMBER)            //array.set(global_float,ID_SELL_STOPLOSS,array.get(global_float,ID_SWING_HIGH))            array.set(global_float,ID_SELL_STOPLOSS,high)            strategy.entry("Enter Short", strategy.short,stop=array.get(global_float,ID_SELL_ENTRY))            array.set(global_int,ID_STATE,PENDING_ENTRY_SHORT)            strategy.exit("Stop Out",from_entry="Enter Short",stop=array.get(global_float,ID_SELL_STOPLOSS))    else if (array.get(global_int,ID_STATE) == BB_BREAK_UP)        if (PullbackCandleShort())            //array.set(global_int,ID_STATE,RETRACE_BAR_DOWN)            array.set(global_float,ID_SELL_ENTRY,low)            array.set(global_float,ID_SELL_STOPLOSS,high)            strategy.entry("Enter Short", strategy.short,stop=array.get(global_float,ID_SELL_ENTRY))            array.set(global_int,ID_STATE,PENDING_ENTRY_SHORT)    else if (array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT)         strategy.cancel("Enter Short")        array.set(global_int,ID_STATE,NO_SETUP)//if (array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT) //    strategy.exit("Stop Out",from_entry="Enter Short",stop=array.get(global_float,ID_SELL_STOPLOSS))if StateInLongTrade()    if (LongTakeProfitHit())         strategy.close("Enter Long",comment="Take Profit")        array.set(global_int,ID_STATE,NO_SETUP)else if StateInShortTrade()    if (ShortTakeProfitHit())        strategy.close("Enter Short",comment="Take Profit")        array.set(global_int,ID_STATE,NO_SETUP)state := array.get(global_int,ID_STATE)buy_entry_price := array.get(global_float,ID_BUY_ENTRY)sell_entry_price := array.get(global_float,ID_SELL_ENTRY)buy_stoploss_price := array.get(global_float,ID_BUY_STOPLOSS)sell_stoploss_price := array.get(global_float,ID_SELL_STOPLOSS)themin := minval(open,close)themax := maxval(open,close)plotchar(state, "State", "", location = location.top)plotchar(themin, "TheMin", "", location = location.top)plotchar(themax, "TheMax", "", location = location.top)plotchar(upperBBValue, "UpperBB", "", location = location.top)plotchar(lowerBBValue, "LowerBB", "", location = location.top)plotchar(buy_stoploss_price, "buy stoploss", "", location = location.top)plotchar(sell_stoploss_price, "sell stoploss", "", location = location.top)swing_low := array.get(global_float,ID_SWING_LOW)plotchar(swing_low, "SwingLow", "", location = location.top)