Pine Script v4 · Strategy
Double Bollinger Strategy
A Pine Script v4 strategy built on Lowest (10), Highest (10) and Valuewhen (bought, LL). It has 12 order rules, 8 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 0.04 commission. 17 settings; defaults include Strategy Direction 0, RSI Length 14 and Slow BB Band Length 45.
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 Double Bollinger Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 15 of 15 trades.
- How did Double Bollinger Strategy do on BTCUSDT 1D with default settings?
- −29.58%
- From 26 Jan 2024 to 21 Oct 2026, over 61 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Double Bollinger 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 Double Bollinger Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 143, 144.
- Does Double Bollinger Strategy run in Zeal Terminal?
- Yes
- It compiles in 39 ms and runs 1,000 bars in 108 ms, in the browser.
BTCUSDT · 1D · default settings
- Slow BB Upper Band
- Slow BB Lower Band
- Fast BB Upper Band
- Fast BB Lower Band
- SL
- SSL
- Bullish Setup
- Bearish Setup
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −29.58%
- −$2,958.28
- Buy and hold
- +102.5%
- same period
- Closed trades
- 61
- 13 won · 48 lost
- Profitable
- 21.3%
- of closed trades
- Profit factor
- 0.66
- gross profit ÷ gross loss
- Max drawdown
- 50.14%
- −$5,014.45
One run with the author's default settings, $10,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
2 settings do nothing
“-----------------Strategy Inputs-------------------”, “-----------------General Inputs-------------------” are declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
Uses an argument v6 removed
when = on line 102, 103, 105, 106, 109, 110, 112, 113, 115, 116, 143, 144. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 85
transp = on line 85, 90. v5 folds the transparency into the colour with color.new(c, transp).
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 lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, atr → ta.atr, rsi → ta.rsi, bb → ta.bb, crossover → ta.crossover, crossunder → ta.crossunder.
- 12 strategy calls use the when = argument (line 102, 103, 105, 106, 109, 110, 112, 113, 115, 116, 143, 144). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 61 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 24: //@version=4 → //@version=5
- Line 33: input(type = input.integer) → input.int()
- Line 55: lowest → ta.lowest
- Line 56: highest → ta.highest
- Line 57: valuewhen → ta.valuewhen
- Line 58: valuewhen → ta.valuewhen
14 more edits
- Line 64: atr → ta.atr
- Line 67: valuewhen → ta.valuewhen
- Line 68: valuewhen → ta.valuewhen
- Line 74: valuewhen → ta.valuewhen
- Line 75: valuewhen → ta.valuewhen
- Line 80: rsi → ta.rsi
- Line 82: bb → ta.bb
- Line 85: transp = 95 → color.new(color.blue, 95)
- Line 87: bb → ta.bb
- Line 90: transp = 95 → color.new(color.white, 95)
- Line 91: crossover → ta.crossover
- Line 92: crossunder → ta.crossunder
- Line 123: valuewhen → ta.valuewhen
- Line 135: valuewhen → ta.valuewhen
⋯// © tweakerID-//@version=4+//@version=5strategy("Double Bollinger Strategy", ⋯ slippage=0)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯// Price Action Stop and Take Profit-LL=(lowest(i_SPL))*(1-i_PercIncrement)+LL=(ta.lowest(i_SPL))*(1-i_PercIncrement)-HH=(highest(i_SPL))*(1+i_PercIncrement)+HH=(ta.highest(i_SPL))*(1+i_PercIncrement)-LL_price = valuewhen(bought, LL, 0)+LL_price = ta.valuewhen(bought, LL, 0)-HH_price = valuewhen(bought, HH, 0)+HH_price = ta.valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na ⋯// ATR Stop-ATR=atr(i_ATR)*i_ATRMult+ATR=ta.atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATR-ATRLongStop = valuewhen(bought, ATRLong, 0)+ATRLongStop = ta.valuewhen(bought, ATRLong, 0)-ATRShortStop = valuewhen(bought, ATRShort, 0)+ATRShortStop = ta.valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ⋯// Strategy Stop-float LongStop = valuewhen(bought,low[1],0)*(1-i_PercIncrement)+float LongStop = ta.valuewhen(bought,low[1],0)*(1-i_PercIncrement)-float ShortStop = valuewhen(bought,high[1],0)*(1+i_PercIncrement)+float ShortStop = ta.valuewhen(bought,high[1],0)*(1+i_PercIncrement)float StratTP = na⋯//RSI-RSI=rsi(close, i_RSI)+RSI=ta.rsi(close, i_RSI)//BOLL1-[middleS, upperS, lowerS] = bb(close, lengthS, 1)+[middleS, upperS, lowerS] = ta.bb(close, lengthS, 1)p1 = plot(upperS, "Slow BB Upper Band", color=color.teal)p2 = plot(lowerS, "Slow BB Lower Band", color=color.teal)-fill(p1, p2, title = "Slow BB Background", color=color.blue, transp=95)+fill(p1, p2, title = "Slow BB Background", color=color.new(color.blue, 95))//BOLL2-[middleF, upperF, lowerF] = bb(close, lengthF, 1)+[middleF, upperF, lowerF] = ta.bb(close, lengthF, 1)p1F = plot(upperF, "Fast BB Upper Band", color=color.gray)p2F = plot(lowerF, "Fast BB Lower Band", color=color.gray)-fill(p1F, p2F, title = "Fast BB Background", color=color.white, transp=95)+fill(p1F, p2F, title = "Fast BB Background", color=color.new(color.white, 95))-BUY = bar_index > 40 and (RSI > 50) and (close > upperF) and crossover(close, upperS)+BUY = bar_index > 40 and (RSI > 50) and (close > upperF) and ta.crossover(close, upperS)-SELL = bar_index > 40 and (RSI < 50) and (close < lowerF) and crossunder(close, lowerS) +SELL = bar_index > 40 and (RSI < 50) and (close < lowerF) and ta.crossunder(close, lowerS) longexit=close < upperF⋯//TrailingStop-dif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0))+dif=(ta.valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0)) -strategy.position_avg_price⋯var Ststop = float(na)-Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0 +Sdif=strategy.position_avg_price-(ta.valuewhen(strategy.position_size<0 and strategy.position_size[1]>=0, low,0))⋯Same 61 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 36: input() → input.bool()
- Line 37: input() → input.int()
- Line 38: input() → input.int()
- Line 39: input() → input.int()
- Line 41: input() → input.bool()
- Line 43: input() → input.bool()
22 more edits
- Line 44: input() → input.string()
- Line 45: input() → input.int()
- Line 46: input() → input.int()
- Line 47: input() → input.int()
- Line 48: input() → input.int()
- Line 49: input() → input.int()
- Line 50: input() → input.bool()
- Line 96: input() → input.bool()
- Line 97: input() → input.bool()
- Line 98: input() → input.bool()
- Line 102: when = SELL and strategy.position_size == 0 → if block
- Line 103: when = BUY and strategy.position_size == 0 → if block
- Line 105: when = SELL → if block
- Line 106: when = BUY → if block
- Line 109: when = BUY and strategy.position_size == 0 → if block
- Line 110: when = SELL and strategy.position_size == 0 → if block
- Line 112: when = BUY → if block
- Line 113: when = SELL → if block
- Line 115: when = longexit → if block
- Line 116: when = shortexit → if block
- Line 143: when = i_SL → if block
- Line 144: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------") +title1=input.bool(true, "-----------------Strategy Inputs-------------------") -i_RSI=input(14, title="RSI Length")+i_RSI=input.int(14, title="RSI Length")-lengthS = input(45, minval=1, title="Slow BB Band Length")+lengthS = input.int(45, minval=1, title="Slow BB Band Length")-lengthF = input(31, minval=1, title="Fast BB Band Length")+lengthF = input.int(31, minval=1, title="Fast BB Band Length")/////////////////////// BACKTESTER /////////////////////////////////////////////-title2=input(true, "-----------------General Inputs-------------------") +title2=input.bool(true, "-----------------General Inputs-------------------") // Backtester General Inputs-i_SL=input(true, title="Use Stop Loss and Take Profit")+i_SL=input.bool(true, title="Use Stop Loss and Take Profit")-i_SLType=input(defval="Strategy Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])+i_SLType=input.string(defval="Strategy Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])-i_SPL=input(defval=10, title="Swing Point Lookback")+i_SPL=input.int(defval=10, title="Swing Point Lookback")-i_PercIncrement=input(defval=1, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.int(defval=1, step=.1, title="Swing Point SL Perc Increment")*0.01-i_ATR = input(14, title="ATR Length")+i_ATR = input.int(14, title="ATR Length")-i_ATRMult = input(5, step=.1, title="ATR Multiple")+i_ATRMult = input.int(5, step=.1, title="ATR Multiple")-i_TPRRR = input(2, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.int(2, step=.1, title="Take Profit Risk Reward Ratio")-TS=input(false, title="Trailing Stop")+TS=input.bool(false, title="Trailing Stop")// Bought and Sold Boolean Signal⋯//Trading Inputs-i_strategyClose=input(true, title="Use Strategy Close Logic")+i_strategyClose=input.bool(true, title="Use Strategy Close Logic")-DPR=input(true, "Allow Direct Position Reverse")+DPR=input.bool(true, "Allow Direct Position Reverse")-reverse=input(false, "Reverse Trades")+reverse=input.bool(false, "Reverse Trades")// Entries⋯ if not DPR- strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)+ if SELL and strategy.position_size == 0+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)+ if BUY and strategy.position_size == 0+ strategy.entry("short", strategy.short) else - strategy.entry("long", strategy.long, when=SELL)+ if SELL+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=BUY)+ if BUY+ strategy.entry("short", strategy.short)else if not DPR - strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)+ if BUY and strategy.position_size == 0+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)+ if SELL and strategy.position_size == 0+ strategy.entry("short", strategy.short) else- strategy.entry("long", strategy.long, when=BUY)+ if BUY+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=SELL)+ if SELL+ strategy.entry("short", strategy.short)if i_strategyClose- strategy.close("long", when=longexit)+ if longexit+ strategy.close("long")- strategy.close("short", when=shortexit)+ if shortexit+ strategy.close("short") ⋯ Ststop := na-strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)+if i_SL+ strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL)-strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)+if i_SL+ strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL)/////////////////////// PLOTS //////////////////////////////////////////////////⋯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: 61 before, 22 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.
⋯// © tweakerID-//@version=5+//@version=6strategy("Double Bollinger Strategy", ⋯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 |
|---|---|---|---|
| Strategy Direction | 0 | int (written input.integer) · min -1 · max 1 | line 34 |
| -----------------Strategy Inputs------------------- | true | bool | unused |
| RSI Length | 14 | int | RSI |
| Slow BB Band Length | 45 | int · min 1 | middleS upperS lowerS |
| Fast BB Band Length | 31 | int · min 1 | middleF upperF lowerF |
| -----------------General Inputs------------------- | true | bool | unused |
| Use Stop Loss and Take Profit | true | bool | exit TP & SL SL SSL TP STP |
| Type Of Stop | Strategy Stop | string · options ["Strategy Stop", "Swing Lo/Hi", "ATR Stop"] | SL SSL TP STP |
| Swing Point Lookback | 10 | int | LL HH |
| Swing Point SL Perc Increment | 1 | int · step .1 | LL HH LongStop ShortStop |
| ATR Length | 14 | int | ATR |
| ATR Multiple | 5 | int · step .1 | ATR |
| Take Profit Risk Reward Ratio | 2 | int · step .1 | tp stp ATRtp ATRstp |
| Trailing Stop | false | bool | exit TP & SL SL SSL |
| Use Strategy Close Logic | true | bool | close long close short line 114 |
| Allow Direct Position Reverse | true | bool | entry long entry short entry long entry short entry long entry short entry long entry short line 101 line 108 |
| Reverse Trades | false | bool | line 100 |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Swing Point Lookback (10)LL · line 55 - Highest (
highest,ta.highestin v5)Swing Point Lookback (10)HH · line 56 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, LL, 0LL_price · line 57 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, HH, 0HH_price · line 58 - ATR (
atr,ta.atrin v5)ATR Length (14)ATR · line 64 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRLong, 0ATRLongStop · line 67 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRShort, 0ATRShortStop · line 68 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, low[1], 0LongStop · line 74 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, high[1], 0ShortStop · line 75 - RSI (
rsi,ta.rsiin v5)close, RSI Length (14)RSI · line 80 - BB (
bb,ta.bbin v5)close, Slow BB Band Length (45), 1middleS · line 82 - BB (
bb,ta.bbin v5)close, Slow BB Band Length (45), 1upperS · line 82 - BB (
bb,ta.bbin v5)close, Slow BB Band Length (45), 1lowerS · line 82 - BB (
bb,ta.bbin v5)close, Fast BB Band Length (31), 1middleF · line 87 - BB (
bb,ta.bbin v5)close, Fast BB Band Length (31), 1upperF · line 87 - BB (
bb,ta.bbin v5)close, Fast BB Band Length (31), 1lowerF · line 87
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 71 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 long long | SELL and strategy.position_size == 0 | On | 102 |
| Open short short | BUY and strategy.position_size == 0 | On | 103 |
| Open long long | SELLbar_index > 40 and (RSI < 50) and (close < lowerF) and crossunder(close, lowerS) | On | 105 |
| Open short short | BUYbar_index > 40 and (RSI > 50) and (close > upperF) and crossover(close, upperS) | On | 106 |
| Open long long | BUY and strategy.position_size == 0 | On | 109 |
| Open short short | SELL and strategy.position_size == 0 | On | 110 |
| Open long long | BUYbar_index > 40 and (RSI > 50) and (close > upperF) and crossover(close, upperS) | On | 112 |
| Open short short | SELLbar_index > 40 and (RSI < 50) and (close < lowerF) and crossunder(close, lowerS) | On | 113 |
| Close long | longexitclose < upperF | On “Use Strategy Close Logic” | 115 |
| Close short | shortexitclose > lowerF | On “Use Strategy Close Logic” | 116 |
| Exit TP & SL stop and limit | i_SL | On | 143 |
| Exit TP & SL stop and limit | i_SL | On | 144 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −29.6% | +102.5% | 61 | 21% | 0.66 | 50.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +3.2% | +5.5% | 50 | 18% | 1.08 | 16.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +44.4% | +9.8% | 49 | 29% | 1.32 | 29.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +14.4% | +8.4% | 54 | 22% | 1.23 | 20.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −4.5% | +16.7% | 50 | 36% | 0.96 | 45.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1.2% | +21.5% | 50 | 18% | 0.97 | 15.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.6% | +148.3% | 41 | 27% | 0.96 | 23.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +7.1% | +17.1% | 52 | 31% | 1.22 | 9.3% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (RSI Length 24, Slow BB Band Length 23) made −27.5% before 26 Dec 2025 and +5.6% after it, worse than the defaults' +14.4% after. Tuning on the past did not carry forward. 0% of the 64 combinations made money in-sample and 89% out-of-sample.
| Slow BB Band Length ↓ · RSI Length → | 7 | 8 | 10 | 12 | 14 | 17 | 20 | 24 |
|---|---|---|---|---|---|---|---|---|
| 23 | −33% | −33% | −33% | −33% | −33% | −33% | −30% | −27% |
| 27 | −39% | −39% | −39% | −39% | −39% | −39% | −36% | −34% |
| 31 | −42% | −42% | −42% | −42% | −42% | −42% | −40% | −35% |
| 38 | −33% | −33% | −33% | −33% | −33% | −33% | −33% | −33% |
| 45 | −44% | −44% | −44% | −44% | −44% | −44% | −44% | −44% |
| 54 | −41% | −41% | −41% | −41% | −41% | −41% | −41% | −41% |
| 63 | −41% | −41% | −41% | −41% | −41% | −41% | −41% | −41% |
| 77 | −28% | −28% | −28% | −28% | −28% | −28% | −28% | −28% |
| Slow BB Band Length ↓ · RSI Length → | 7 | 8 | 10 | 12 | 14 | 17 | 20 | 24 |
|---|---|---|---|---|---|---|---|---|
| 23 | −2% | −2% | −2% | −2% | −2% | −2% | −1% | +6% |
| 27 | +11% | +11% | +11% | +11% | +11% | +11% | +12% | +19% |
| 31 | +6% | +6% | +6% | +6% | +6% | +5% | +6% | +15% |
| 38 | +11% | +11% | +11% | +11% | +11% | +11% | +12% | +12% |
| 45 | +14% | +14% | +14% | +14% | +14% | +14% | +14% | +16% |
| 54 | +23% | +23% | +23% | +23% | +23% | +23% | +23% | +23% |
| 63 | +26% | +26% | +26% | +26% | +26% | +26% | +26% | +26% |
| 77 | +27% | +27% | +27% | +27% | +27% | +27% | +27% | +27% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 22 | 9% | −$2,816.89 |
| Sideways market | 26 | 35% | $231.78 |
| Falling market | 13 | 15% | −$373.16 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
55.4%
The 95th percentile of the worst drawdown when the same 61 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 33.3% to 55.4%; the tick is what actually happened, 49.6%. Order luck alone moves it this much.
All 61 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 1 Apr 2024 71,280.00 | 2 Apr 2024 69,649.80 | 1 | −$236.52 |
| long | 9 Apr 2024 71,620.00 | 10 Apr 2024 69,146.00 | 1 | −$344.80 |
| short | 14 Apr 2024 63,924.50 | 15 Apr 2024 65,661.90 | 1 | −$263.51 |
| short | 16 Apr 2024 63,420.00 | 21 Apr 2024 64,940.60 | 5 | −$226.83 |
| short | 25 Apr 2024 64,289.60 | 26 Apr 2024 64,498.30 | 1 | −$36.13 |
| short | 27 Apr 2024 63,770.00 | 30 Apr 2024 63,866.00 | 3 | −$20.50 |
| short | 1 May 2024 60,672.00 | 4 May 2024 62,882.00 | 3 | −$330.25 |
| short | 11 May 2024 60,800.00 | 13 May 2024 61,484.00 | 2 | −$102.92 |
| long | 21 May 2024 71,446.60 | 30 May 2024 67,652.40 | 9 | −$454.52 |
| short | 23 Jun 2024 64,262.00 | 1 Jul 2024 62,772.00 | 8 | $178.74 |
| long | 22 Jul 2024 68,165.40 | 24 Jul 2024 65,119.20 | 2 | −$371.01 |
| long | 27 Jul 2024 67,908.00 | 31 Jul 2024 66,188.00 | 4 | −$203.43 |
| short | 5 Aug 2024 58,161.00 | 8 Aug 2024 61,728.80 | 3 | −$471.56 |
| short | 2 Sep 2024 57,301.80 | 2 Sep 2024 58,313.40 | 0 | −$131.34 |
| short | 6 Sep 2024 56,180.00 | 10 Sep 2024 57,042.00 | 4 | −$112.77 |
| long | 19 Sep 2024 61,760.00 | 1 Oct 2024 63,327.60 | 12 | $168.81 |
| long | 15 Oct 2024 66,084.00 | 24 Oct 2024 66,668.60 | 9 | $56.62 |
| long | 12 Dec 2024 101,125.00 | 19 Dec 2024 100,204.00 | 7 | −$70.27 |
| short | 31 Dec 2024 92,792.10 | 2 Jan 2025 95,974.80 | 2 | −$246.67 |
| long | 7 Jan 2025 102,236.00 | 8 Jan 2025 96,954.60 | 1 | −$355.42 |
| short | 10 Jan 2025 92,552.50 | 11 Jan 2025 94,726.10 | 1 | −$156.05 |
| long | 18 Jan 2025 104,077.00 | 27 Jan 2025 102,620.00 | 9 | −$92.74 |
| long | 30 Jan 2025 103,733.00 | 1 Feb 2025 102,430.00 | 2 | −$82.51 |
| short | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | −$185.74 |
| short | 4 Mar 2025 86,221.20 | 6 Mar 2025 90,606.00 | 2 | −$305.22 |
| short | 7 Apr 2025 78,430.00 | 10 Apr 2025 82,615.20 | 3 | −$303.50 |
| short | 11 Apr 2025 79,607.30 | 12 Apr 2025 83,423.80 | 1 | −$258.33 |
| long | 22 Apr 2025 87,516.20 | 29 May 2025 107,782.00 | 37 | $1,162.49 |
| long | 10 Jun 2025 110,263.00 | 12 Jun 2025 108,645.00 | 2 | −$95.92 |
| short | 22 Jun 2025 102,120.00 | 23 Jun 2025 105,022.00 | 1 | −$178.49 |
| long | 3 Jul 2025 108,850.00 | 5 Jul 2025 107,984.00 | 2 | −$51.84 |
| long | 7 Jul 2025 109,204.00 | 8 Jul 2025 108,263.00 | 1 | −$55.30 |
| long | 9 Jul 2025 108,923.00 | 26 Jul 2025 117,614.00 | 17 | $459.57 |
| long | 11 Aug 2025 119,294.00 | 12 Aug 2025 118,686.00 | 1 | −$37.03 |
| long | 13 Aug 2025 120,134.00 | 15 Aug 2025 118,295.00 | 2 | −$100.52 |
| short | 20 Aug 2025 112,873.00 | 23 Aug 2025 116,936.00 | 3 | −$226.10 |
| short | 25 Aug 2025 113,494.00 | 3 Sep 2025 111,240.00 | 9 | $112.79 |
| short | 26 Sep 2025 108,994.00 | 29 Sep 2025 112,164.00 | 3 | −$180.21 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 112,827.00 | 8 | −$289.02 |
| short | 17 Oct 2025 108,194.00 | 21 Oct 2025 110,532.00 | 4 | −$124.63 |
| short | 22 Oct 2025 108,298.00 | 24 Oct 2025 110,078.00 | 2 | −$93.75 |
| short | 31 Oct 2025 108,323.00 | 1 Nov 2025 109,608.00 | 1 | −$67.67 |
| short | 4 Nov 2025 106,583.00 | 11 Nov 2025 106,011.00 | 7 | $24.09 |
| short | 12 Nov 2025 103,059.00 | 28 Nov 2025 91,333.90 | 16 | $598.75 |
| short | 16 Dec 2025 86,432.10 | 17 Dec 2025 87,863.40 | 1 | −$102.40 |
| short | 18 Dec 2025 86,243.20 | 18 Dec 2025 89,057.70 | 0 | −$193.80 |
| long | 5 Jan 2026 91,529.70 | 8 Jan 2026 91,364.20 | 3 | −$14.61 |
| long | 14 Jan 2026 95,414.00 | 20 Jan 2026 92,631.00 | 6 | −$167.33 |
| short | 26 Jan 2026 86,670.40 | 27 Jan 2026 88,347.10 | 1 | −$109.20 |
| short | 30 Jan 2026 84,650.20 | 21 Feb 2026 68,020.00 | 22 | $1,039.24 |
| long | 17 Mar 2026 74,884.70 | 18 Mar 2026 71,547.70 | 1 | −$287.85 |
| short | 28 Mar 2026 66,407.30 | 1 Apr 2026 68,284.50 | 4 | −$176.24 |
| long | 8 Apr 2026 71,924.20 | 9 Apr 2026 71,069.90 | 1 | −$74.57 |
| long | 14 Apr 2026 74,418.00 | 29 Apr 2026 76,342.80 | 15 | $145.56 |
| long | 15 May 2026 81,090.00 | 16 May 2026 79,113.20 | 1 | −$149.88 |
| short | 28 May 2026 74,449.30 | 15 Jun 2026 65,746.40 | 18 | $674.26 |
| long | 19 Jul 2026 64,834.20 | 20 Jul 2026 63,247.80 | 1 | −$163.66 |
| long | 27 Jul 2026 65,400.00 | 27 Jul 2026 63,637.20 | 0 | −$175.22 |
| short | 17 Aug 2026 62,900.00 | 18 Aug 2026 64,532.10 | 1 | −$164.31 |
| long | 20 Aug 2026 69,334.80 | 8 Sep 2026 79,112.00 | 19 | $837.65 |
| long | 19 Sep 2026 80,883.90 | 1 Oct 2026 83,623.60 | 12 | $225.25 |
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 |
|---|---|---|---|---|---|
| Double Bollinger Strategy this page | — | v4 strategy | −29.6% | 61 | 50.1% |
| Delayed RSI Strategy by tweakerID | lowest highest valuewhen atr rsi | v4 strategy | −40.4% | 7 | 42.2% |
| Positive Bars - Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −40.3% | 7 | 54.7% |
| Big Bar Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −56.6% | 13 | 57.1% |
| SuperTrend Multi Time Frame Long and Short Trading Strategy by ranga_technologies | atr highest lowest valuewhen | v5 strategy | No trades on this market | ||
| Dynamic Stop Loss Demo by Tindtily | highest lowest rsi atr | v5 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 39 ms | Yes 1,000 bars in 108 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// From "Bitcoin Trading Strategies: Algorithmic Trading Strategies For Bitcoin And Cryptocurrency That Work" by David Hanson.// "Double Bolinger Band Scalping System // Recommended Timeframe: 1 minute or 5 minute // Required Indicators: // - RSI with a length of 14 (default settings) // - Bolinger band #1 settings: Length = 50, stDev = 1 Hide the basis/middle line (basis line not needed for this strategy) // Note: This is the slower bolinger band in the directions // - Bolinger band #2 settings: Length 20, stDev = 1 Hide the basis/middle line (basis line not needed for this strategy) // Note: This is the faster bolinger band in the directions // Enter Long/Buy Trade When: // - RSI is above the level 50 // - A candle closes above the top of the faster bolinger band // Enter a long when a candle then closes above the top of the slower bolinger band, and price is above the top of both bands // Place a stop loss under the low of the entry candle Example of a long trade using this strategy // Exit Long Trade When: A candle closes below the top band of the fast bolinger band // Enter Short/Sell Trade When: // - RSI is below the level 50 // - A candle closes below the bottom of the faster bolinger band // Enter a short when a candle then closes below the bottom of the slower bolinger band, and price is below both bands // Place a stop loss above the high of the entry candle Example of a short trade using this strategy // Exit Short Trade When: Price closes inside the bottom of the faster bolinger band"// © tweakerID//@version=4strategy("Double Bollinger Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04, calc_on_every_tick=false, slippage=0)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))/////////////////////// STRATEGY INPUTS ////////////////////////////////////////title1=input(true, "-----------------Strategy Inputs-------------------") i_RSI=input(14, title="RSI Length")lengthS = input(45, minval=1, title="Slow BB Band Length")lengthF = input(31, minval=1, title="Fast BB Band Length")/////////////////////// BACKTESTER /////////////////////////////////////////////title2=input(true, "-----------------General Inputs-------------------") // Backtester General Inputsi_SL=input(true, title="Use Stop Loss and Take Profit")i_SLType=input(defval="Strategy Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])i_SPL=input(defval=10, title="Swing Point Lookback")i_PercIncrement=input(defval=1, step=.1, title="Swing Point SL Perc Increment")*0.01i_ATR = input(14, title="ATR Length")i_ATRMult = input(5, step=.1, title="ATR Multiple")i_TPRRR = input(2, step=.1, title="Take Profit Risk Reward Ratio")TS=input(false, title="Trailing Stop")// Bought and Sold Boolean Signalbought = strategy.position_size > strategy.position_size[1] or strategy.position_size < strategy.position_size[1]// Price Action Stop and Take ProfitLL=(lowest(i_SPL))*(1-i_PercIncrement)HH=(highest(i_SPL))*(1+i_PercIncrement)LL_price = valuewhen(bought, LL, 0)HH_price = valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na entry_HH_price = strategy.position_size < 0 ? HH_price : na tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRRstp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR// ATR StopATR=atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATRATRLongStop = valuewhen(bought, ATRLong, 0)ATRShortStop = valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ShortSL_ATR_price = strategy.position_size < 0 ? ATRShortStop : na ATRtp=strategy.position_avg_price + (strategy.position_avg_price - LongSL_ATR_price)*i_TPRRRATRstp=strategy.position_avg_price - (ShortSL_ATR_price - strategy.position_avg_price)*i_TPRRR// Strategy Stopfloat LongStop = valuewhen(bought,low[1],0)*(1-i_PercIncrement)float ShortStop = valuewhen(bought,high[1],0)*(1+i_PercIncrement)float StratTP = nafloat StratSTP = na/////////////////////// STRATEGY LOGIC ///////////////////////////////////////////RSIRSI=rsi(close, i_RSI)//BOLL1[middleS, upperS, lowerS] = bb(close, lengthS, 1)p1 = plot(upperS, "Slow BB Upper Band", color=color.teal)p2 = plot(lowerS, "Slow BB Lower Band", color=color.teal)fill(p1, p2, title = "Slow BB Background", color=color.blue, transp=95)//BOLL2[middleF, upperF, lowerF] = bb(close, lengthF, 1)p1F = plot(upperF, "Fast BB Upper Band", color=color.gray)p2F = plot(lowerF, "Fast BB Lower Band", color=color.gray)fill(p1F, p2F, title = "Fast BB Background", color=color.white, transp=95)BUY = bar_index > 40 and (RSI > 50) and (close > upperF) and crossover(close, upperS)SELL = bar_index > 40 and (RSI < 50) and (close < lowerF) and crossunder(close, lowerS) longexit=close < upperFshortexit=close > lowerF//Trading Inputsi_strategyClose=input(true, title="Use Strategy Close Logic")DPR=input(true, "Allow Direct Position Reverse")reverse=input(false, "Reverse Trades")// Entriesif reverse if not DPR strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0) strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0) else strategy.entry("long", strategy.long, when=SELL) strategy.entry("short", strategy.short, when=BUY)else if not DPR strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0) strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0) else strategy.entry("long", strategy.long, when=BUY) strategy.entry("short", strategy.short, when=SELL)if i_strategyClose strategy.close("long", when=longexit) strategy.close("short", when=shortexit) SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStopSSL= i_SLType == "Swing Lo/Hi" ? entry_HH_price : i_SLType == "ATR Stop" ? ShortSL_ATR_price : ShortStopTP= i_SLType == "Swing Lo/Hi" ? tp : i_SLType == "ATR Stop" ? ATRtp : StratTPSTP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTP//TrailingStopdif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0)) -strategy.position_avg_pricetrailOffset = strategy.position_avg_price - SLvar tstop = float(na)if strategy.position_size > 0 tstop := high- trailOffset - dif if tstop<tstop[1] tstop:=tstop[1]else tstop := naStrailOffset = SSL - strategy.position_avg_pricevar Ststop = float(na)Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0 and strategy.position_size[1]>=0, low,0))if strategy.position_size < 0 Ststop := low+ StrailOffset + Sdif if Ststop>Ststop[1] Ststop:=Ststop[1]else Ststop := nastrategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)/////////////////////// PLOTS //////////////////////////////////////////////////plot(i_SL and strategy.position_size > 0 and not TS ? SL : i_SL and strategy.position_size > 0 and TS ? tstop : na , title='SL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size < 0 and not TS ? SSL : i_SL and strategy.position_size < 0 and TS ? Ststop : na , title='SSL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)plot(i_SL and strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)// Draw price action setup arrowsplotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.green, title="Bullish Setup", size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup", size=size.auto)