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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Take Proft trigger | OPTION0 | string · options [OPTION0,OPTION1,OPTION2] | line 15 line 17 |
| From | timestamp("23 Feb 2023 00:00 +0000") | time | line 72 |
| Thru | timestamp("09 Apr 2023 00:00 +0000") | time | line 72 |
What it calculates
- SMAsource, length
basis · line 27 - Stdevsource, length
dev · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| cancel Enter Long | (array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG) | On | 149 |
| cancel Enter Short | (array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT) | On | 153 |
| Open Enter Long long | (LongTriggerCondition()) | On | 171 |
| Exit Stop Out stop | (LongTriggerCondition()) | On | 173 |
| Open Enter Long long | (PullbackCandleLong()) | On | 178 |
| cancel Enter Long | (array.get(global_int,ID_STATE) == PENDING_ENTRY_LONG) | On | 181 |
| Open Enter Short short | (ShortTriggerCondition()) | On | 200 |
| Exit Stop Out stop | (ShortTriggerCondition()) | On | 202 |
| Open Enter Short short | (PullbackCandleShort()) | On | 208 |
| cancel Enter Short | (array.get(global_int,ID_STATE) == PENDING_ENTRY_SHORT) | On | 211 |
| Close Enter Long | (LongTakeProfitHit()) | On | 217 |
| Close Enter Short | (ShortTakeProfitHit()) | On | 221 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| BBPullback1.0.2 this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Double Bollinger Binary Options by Trade_by_DB | sma stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | sma stdev | v4 strategy | −20.4% | 7 | 22.3% |
| I11L Long Put-Call Ratio Inversion by I11L | sma stdev | v5 strategy | No trades on this market | ||
| P-Signal Strategy by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.6% |
| P-Signal Strategy & Alert by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.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
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 78 ms | Yes 1,000 bars in 98 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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)