Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[KL] Double Bollinger Bands Strategy (for Crypto-FOREX)

A Pine Script v4 strategy built on SMA (BOLL_src, BOLL_length), Stdev (BOLL_src, BOLL_length) and Stdev or SMA (close, 20). It has 6 order rules, 2 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. 11 settings; defaults include Alert MSG for buying (Long position) Long +1 entered, Alert MSG for closing (Long position) Long -1 closed and Alert MSG for selling (Short position) Short -1 entered.

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 [KL] Double Bollinger Bands Strategy (for Crypto-FOREX) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 13 of 13 trades.
How did [KL] Double Bollinger Bands Strategy (for Crypto-FOREX) do on BTCUSDT 1D with default settings?
−42.16%
From 26 Jan 2024 to 21 Oct 2026, over 42 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [KL] Double Bollinger Bands Strategy (for Crypto-FOREX) 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.
What alerts does [KL] Double Bollinger Bands Strategy (for Crypto-FOREX) have?
4
LONG_MSG_EXIT; SHORT_MSG_EXIT; LONG_MSG_ENTER; SHORT_MSG_ENTER.
Does [KL] Double Bollinger Bands Strategy (for Crypto-FOREX) use a stop loss?
Yes
strategy.exit sets a stop on line 74, 76.

BTCUSDT · 1D · default settings

  • Basis
  • BOLL Upper1
  • BOLL Lower1
  • BOLL Upper2
  • BOLL Lower2
  • Plot
  • Plot
  • 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 (11)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$54,890$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 merges fill() calls that share a title, so it would draw 1 of this script's 4 fills; this page gives each call its own title to draw all of them. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
−42.16%
−$42,160.40
Buy and hold
+102.5%
same period
Closed trades
42
19 won · 23 lost
Profitable
45.2%
of closed trades
Profit factor
0.61
gross profit ÷ gross loss
Max drawdown
56.81%
−$71,654.00

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

  • Likely bug

    sma(close, 20) ignores the settings line 33

    Line 33 hard-codes 20 where line 36 uses “lookback period for drift calc.”. Changing those settings moves one band but not this one.

    sma(close,20)sma(close, len_drift)
  • Likely bug

    sma(cv, 50) ignores the settings line 48

    Line 48 hard-codes 50 where line 36 uses “lookback period for drift calc.”. Changing those settings moves one band but not this one.

    sma(cv,50)sma(cv, len_drift)
  • Likely bug

    sma(atr14, 5) ignores the settings line 67

    Line 67 hard-codes 5 where line 36 uses “lookback period for drift calc.”. Changing those settings moves one band but not this one.

    sma(atr14,5)sma(atr14, len_drift)
  • Likely bug

    sma(atr14, 5) ignores the settings line 68

    Line 68 hard-codes 5 where line 36 uses “lookback period for drift calc.”. Changing those settings moves one band but not this one.

    sma(atr14,5)sma(atr14, len_drift)
  • Likely bug

    stdev(close, 20) ignores the settings line 33

    Line 33 hard-codes 20 where line 36 uses “lookback period for drift calc.”. Changing those settings moves one band but not this one.

    stdev(close,20)stdev(close, len_drift)
  • 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.

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, stdev → ta.stdev, log → math.log, pow → math.pow, atr → ta.atr, max → math.max, min → math.min.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.string) → input.string()
  • Line 7: input(type = input.string) → input.string()
  • Line 9: input(type = input.string) → input.string()
  • Line 10: input(type = input.string) → input.string()
  • Line 12: input(type = input.time) → input.time()
19 more edits
  • Line 14: input(type = input.time) → input.time()
  • Line 18: sma → ta.sma
  • Line 19: stdev → ta.stdev
  • Line 33: stdev → ta.stdev
  • Line 33: sma → ta.sma
  • Line 35: log → math.log
  • Line 36: sma → ta.sma
  • Line 36: pow → math.pow
  • Line 36: stdev → ta.stdev
  • Line 39: atr → ta.atr
  • Line 39: input(type = input.float) → input.float()
  • Line 45: max → math.max
  • Line 46: min → math.min
  • Line 48: sma → ta.sma
  • Line 53: max → math.max
  • Line 55: min → math.min
  • Line 66: atr → ta.atr
  • Line 67: sma → ta.sma
  • Line 68: sma → ta.sma
⋯// © DojiEmoji (kevinhhl)-//@version=4+//@version=5strategy("[KL] Double BB Strategy",overlay=true,pyramiding=1)ENUM_LONG       = "LONG"-LONG_MSG_ENTER  = input("Long +1 entered", type=input.string, title="Alert MSG for buying (Long position)")+LONG_MSG_ENTER  = input.string("Long +1 entered", title="Alert MSG for buying (Long position)")-LONG_MSG_EXIT   = input("Long -1 closed", type=input.string, title="Alert MSG for closing (Long position)")+LONG_MSG_EXIT   = input.string("Long -1 closed", title="Alert MSG for closing (Long position)")ENUM_SHORT      = "SHORT"-SHORT_MSG_ENTER = input("Short -1 entered", type=input.string, title="Alert MSG for selling (Short position)")+SHORT_MSG_ENTER = input.string("Short -1 entered", title="Alert MSG for selling (Short position)")-SHORT_MSG_EXIT  = input("Short +1 covered", type=input.string, title="Alert MSG for covering (Short position)")+SHORT_MSG_EXIT  = input.string("Short +1 covered", title="Alert MSG for covering (Short position)")// Timeframe {-backtest_timeframe_start    = input(defval = timestamp("01 Apr 2020 13:30 +0000"), title = "Backtest Start Time", type = input.time)+backtest_timeframe_start    = input.time(defval = timestamp("01 Apr 2020 13:30 +0000"), title = "Backtest Start Time")USE_ENDTIME                 = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")-backtest_timeframe_end      = input(defval = timestamp("19 Apr 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)+backtest_timeframe_end      = input.time(defval = timestamp("19 Apr 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")within_timeframe            = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)⋯// Bollinger bands {-BOLL_length     = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length)+BOLL_length     = 20, BOLL_src = close, SMA20 = ta.sma(BOLL_src, BOLL_length)-BOLL_sDEV       = stdev(BOLL_src, BOLL_length)+BOLL_sDEV       = ta.stdev(BOLL_src, BOLL_length)BOLL_upper1     = SMA20 + BOLL_sDEV, BOLL_lower1 = SMA20 - BOLL_sDEV⋯// Quantative methods - used for setting stop losses and entry/exit signals {-cv = stdev(close,20)/sma(close,20)+cv = ta.stdev(close,20)/ta.sma(close,20)len_drift = input(14,title="lookback period for drift calc.")-percentage_chng = log(close/close[1])+percentage_chng = math.log(close/close[1])-drift = sma(percentage_chng, len_drift) - pow(stdev(percentage_chng, len_drift),2) * 0.5+drift = ta.sma(percentage_chng, len_drift) - math.pow(ta.stdev(percentage_chng, len_drift),2) * 0.5// } Quant methods// Trailing stop loss {-ATR_X2_TSL = atr(input(14,title="Length of ATR for trailing stop loss")) * input(2.0,title="ATR Multiplier for trailing stop loss",type=input.float)+ATR_X2_TSL = ta.atr(input(14,title="Length of ATR for trailing stop loss")) * input.float(2.0,title="ATR Multiplier for trailing stop loss")TSL_source_long = low, TSL_source_short = high⋯var pos_opened_short = false // to be updated in MAIN loop-stop_loss_price_long := pos_opened_long ? max(stop_loss_price_long, TSL_source_long - ATR_X2_TSL) : TSL_source_long - ATR_X2_TSL+stop_loss_price_long := pos_opened_long ? math.max(stop_loss_price_long, TSL_source_long - ATR_X2_TSL) : TSL_source_long - ATR_X2_TSL-stop_loss_price_short := pos_opened_short ? min(stop_loss_price_short, TSL_source_short + ATR_X2_TSL) : TSL_source_short + ATR_X2_TSL+stop_loss_price_short := pos_opened_short ? math.min(stop_loss_price_short, TSL_source_short + ATR_X2_TSL) : TSL_source_short + ATR_X2_TSL// tighten TSL-is_consol = cv < sma(cv,50)+is_consol = cv < ta.sma(cv,50)TIGHTEN_TSL = input(true, title="Tighten stop loss when price moves sharply in favorable direction")⋯        if pos_opened_long and cv > cv[1]-            stop_loss_price_long := max(stop_loss_price_long * (1+percentage_chng*0.5), stop_loss_price_long[1])+            stop_loss_price_long := math.max(stop_loss_price_long * (1+percentage_chng*0.5), stop_loss_price_long[1])        if pos_opened_short and cv > cv[1]-            stop_loss_price_short := min(stop_loss_price_long * (1+percentage_chng*0.5), stop_loss_price_short[1])+            stop_loss_price_short := math.min(stop_loss_price_long * (1+percentage_chng*0.5), stop_loss_price_short[1])// Plot TSL⋯above_neutral = close > BOLL_upper1 and close < BOLL_upper2-atr14 = atr(14)+atr14 = ta.atr(14)-entry_signal_long = is_consol and close > BOLL_upper1 and atr14 > sma(atr14,5) and drift > 0+entry_signal_long = is_consol and close > BOLL_upper1 and atr14 > ta.sma(atr14,5) and drift > 0-entry_signal_short = is_consol and close < BOLL_lower1 and atr14 > sma(atr14,5) and drift < 0+entry_signal_short = is_consol and close < BOLL_lower1 and atr14 > ta.sma(atr14,5) and drift < 0// } Signals for entry⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 13: input() → input.bool()
  • Line 34: input() → input.int()
  • Line 39: input() → input.int()
  • Line 49: input() → input.bool()
⋯backtest_timeframe_start    = input.time(defval = timestamp("01 Apr 2020 13:30 +0000"), title = "Backtest Start Time")-USE_ENDTIME                 = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")+USE_ENDTIME                 = input.bool(false,title="Define backtest end-time (If false, will test up to most recent candle)")backtest_timeframe_end      = input.time(defval = timestamp("19 Apr 2021 19:30 +0000"), title = "Backtest End Time (if checked above)")⋯cv = ta.stdev(close,20)/ta.sma(close,20)-len_drift = input(14,title="lookback period for drift calc.")+len_drift = input.int(14,title="lookback period for drift calc.")percentage_chng = math.log(close/close[1])⋯// Trailing stop loss {-ATR_X2_TSL = ta.atr(input(14,title="Length of ATR for trailing stop loss")) * input.float(2.0,title="ATR Multiplier for trailing stop loss")+ATR_X2_TSL = ta.atr(input.int(14,title="Length of ATR for trailing stop loss")) * input.float(2.0,title="ATR Multiplier for trailing stop loss")TSL_source_long = low, TSL_source_short = high⋯is_consol = cv < ta.sma(cv,50)-TIGHTEN_TSL = input(true, title="Tighten stop loss when price moves sharply in favorable direction")+TIGHTEN_TSL = input.bool(true, title="Tighten stop loss when price moves sharply in favorable direction")if TIGHTEN_TSL⋯

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: 42 before, 40 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.

⋯// © DojiEmoji (kevinhhl)-//@version=5+//@version=6strategy("[KL] Double BB Strategy",overlay=true,pyramiding=1)⋯

Settings

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

SettingDefaultType and rangeFeeds
Alert MSG for buying (Long position)Long +1 enteredstringalert
Alert MSG for closing (Long position)Long -1 closedstringalert
Alert MSG for selling (Short position)Short -1 enteredstringalert
Alert MSG for covering (Short position)Short +1 coveredstringalert
Backtest Start Timetimestamp("01 Apr 2020 13:30 +0000")timewithin_timeframe
Define backtest end-time (If false, will test up to most recent candle)falseboolwithin_timeframe
Backtest End Time (if checked above)timestamp("19 Apr 2021 19:30 +0000")timewithin_timeframe
lookback period for drift calc.14intdrift
Length of ATR for trailing stop loss14intstop_loss_price_long stop_loss_price_short
ATR Multiplier for trailing stop loss2.0floatstop_loss_price_long stop_loss_price_short
Tighten stop loss when price moves sharply in favorable directiontrueboolline 50

What it calculates

  • SMA (sma, ta.sma in v5)BOLL_src, BOLL_lengthSMA20 · line 18
  • Stdev (stdev, ta.stdev in v5)BOLL_src, BOLL_lengthBOLL_sDEV · line 19
  • Stdev / SMA (stdev, ta.stdev in v5)close, 20cv · line 33
  • SMA / Stdev (sma, ta.sma in v5)percentage_chng, lookback period for drift calc. (14)drift · line 36
  • ATR (atr, ta.atr in v5)14atr14 · line 66

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 datalen_driftlookback period for dri…setting · 14high · low · closehigh · low · closeprice datalowlowprice datahighhighprice dataATR_X2_TSLATR Multiplier for trai…setting · 2.0timetimeprice databacktest_timeframe_startBacktest Start Timesetting · timestamp("01 Apr 2…backtest_timeframe_endBacktest End Time (if c…setting · timestamp("19 Apr 2…LONG_MSG_EXITAlert MSG for closing (…setting · Long -1 closedSHORT_MSG_EXITAlert MSG for covering …setting · Short +1 coveredLONG_MSG_ENTERAlert MSG for buying (L…setting · Long +1 enteredSHORT_MSG_ENTERAlert MSG for selling (…setting · Short -1 enteredSMA20SMA→ SMA20BOLL_sDEVStdev→ BOLL_sDEVcvStdev / SMA→ cvdriftSMA / Stdev→ driftatr14ATR→ atr14BOLL_src, percentage_chngBOLL_src · percentage_c…2 valuesBOLL_upper1, BOLL_lower1, BOLL_upper2, BOLL_lower2BOLL_upper1 · BOLL_lowe…4 valuesTSL_source_longTSL_source_longvalueTSL_source_shortTSL_source_shortvaluestop_loss_price_longstop_loss_price_longvaluestop_loss_price_shortstop_loss_price_shortvalueTSL_transp_long, TSL_transp_shortTSL_transp_long · TSL_t…2 valuesis_consolis_consolconditionentry_signal_longentry_signal_longconditionentry_signal_shortentry_signal_shortconditionend_of_rallyend_of_rallyconditionwithin_timeframewithin_timeframeconditionis_neutral, below_neutral, above_neutralis_neutral · below_neut…3 conditionsexit:LONGexit LONGstrategy.exitexit:SHORTexit SHORTstrategy.exitclose:LONGClose LONGstrategy.closeclose:SHORTClose SHORTstrategy.closeentry:LONGOpen LONGstrategy.entryentry:SHORTOpen SHORTstrategy.entryplot:22Basisplotplot:23BOLL Upper1plotplot:24BOLL Lower1plotplot:25BOLL Upper2plotplot:26BOLL Lower2plotfill:BackgroundBackgroundfill × 4plot:59plotplotplot:60plotplotalert:81alertalertalert:85alertalertalert:90alertalertalert:94alertalert

Order rules

OrderFires whenBy defaultLine
Exit LONG stoppos_opened_longOn74
Exit SHORT stoppos_opened_shortOn76
Close LONGpos_opened_long and (TSL_source_long <= stop_loss_price_long or end_of_rally and not is_consol)On82
Close SHORTpos_opened_short and (TSL_source_short >= stop_loss_price_short)On86
Open LONG longentry_signal_long and close > stop_loss_price_longOn91
Open SHORT shortentry_signal_shortOn95

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(no title)alertLONG_MSG_EXIT81
(no title)alertSHORT_MSG_EXIT85
(no title)alertLONG_MSG_ENTER90
(no title)alertSHORT_MSG_ENTER94

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

13/13trades 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−42.2%+102.5%4245%0.6156.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−11.0%+5.5%4547%0.6514.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.5%+9.8%3944%1.351.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.5%+8.4%4134%0.530.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.2%+16.7%3667%2.230.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%4452%1.060.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%3155%1.020.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%3244%1.630.0%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 market1850%−$5,232.52
Sideways market1450%−$6,542.03
Falling market1030%−$30,385.90

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

How bad could the drawdown be?

57.5%

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

0%66%
All 42 trades
SideEntryExitBarsP&L
short13 Apr 2024 67,116.5015 May 2024 65,956.8032$1,159.74
long16 May 2024 66,206.5027 May 2024 68,507.7011$2,301.16
short14 Jun 2024 66,773.0023 Jun 2024 64,262.009$2,511.00
short3 Aug 2024 61,498.306 Aug 2024 54,018.803$7,479.52
long24 Aug 2024 64,037.2027 Aug 2024 58,361.603−$5,675.62
short6 Sep 2024 56,180.009 Sep 2024 54,869.903$1,310.05
long18 Sep 2024 60,314.001 Oct 2024 61,451.3013$1,137.28
short11 Oct 2024 60,326.4014 Oct 2024 65,339.603−$5,013.15
long15 Oct 2024 66,084.0023 Oct 2024 67,426.008$1,342.01
long31 Oct 2024 72,344.804 Nov 2024 67,264.604−$5,080.12
long7 Nov 2024 75,572.0019 Dec 2024 97,438.7042$21,866.70
short10 Jan 2025 92,552.5016 Jan 2025 100,497.006−$7,944.86
long16 Jan 2025 100,497.0027 Jan 2025 102,620.0011$2,122.66
short5 Feb 2025 97,763.1010 Feb 2025 96,462.805$1,300.39
short25 Feb 2025 91,552.9027 Feb 2025 84,250.102$7,302.79
short3 Apr 2025 82,516.3022 Apr 2025 88,506.8019−$5,990.50
long26 May 2025 109,004.005 Jun 2025 102,688.0010−$6,316.04
short6 Jun 2025 101,509.0010 Jun 2025 110,263.004−$8,754.33
long10 Jun 2025 110,263.0020 Jun 2025 102,491.0010−$7,771.78
short21 Jun 2025 103,298.002 Jul 2025 109,550.0011−$6,252.03
long3 Jul 2025 108,850.001 Aug 2025 115,764.0029$6,914.48
short1 Aug 2025 115,764.003 Aug 2025 114,313.002$1,451.21
long13 Aug 2025 120,134.0019 Aug 2025 113,284.006−$6,850.10
short22 Aug 2025 112,500.0027 Aug 2025 111,763.005$736.78
short26 Sep 2025 108,994.0029 Sep 2025 114,301.003−$5,306.60
long2 Oct 2025 118,595.0010 Oct 2025 119,208.008$612.62
short5 Nov 2025 101,497.009 Nov 2025 102,313.004−$815.72
long4 Dec 2025 93,429.9018 Dec 2025 86,243.2014−$7,186.72
short18 Dec 2025 86,243.2019 Dec 2025 85,516.401$726.82
long7 Jan 2026 93,748.0019 Jan 2026 93,673.1012−$74.83
short28 Feb 2026 65,872.105 Mar 2026 72,666.805−$6,794.68
long5 Mar 2026 72,666.8022 Mar 2026 67,453.3017−$5,213.45
short28 Mar 2026 66,407.307 Apr 2026 72,451.4010−$6,044.14
long8 Apr 2026 71,924.2013 Apr 2026 70,741.605−$1,182.66
long8 May 2026 80,006.0018 May 2026 76,410.1010−$3,595.85
short24 May 2026 76,752.0029 May 2026 73,617.505$3,134.48
short25 Jun 2026 61,078.006 Jul 2026 64,694.7011−$3,616.71
long15 Jul 2026 65,044.001 Aug 2026 62,887.9017−$2,156.11
short1 Aug 2026 62,887.902 Aug 2026 62,823.701$64.23
short12 Sep 2026 77,225.7013 Sep 2026 77,278.701−$53.02
short16 Sep 2026 75,644.5017 Sep 2026 76,206.001−$561.52
long19 Sep 2026 80,883.9029 Sep 2026 83,500.0010$2,616.15

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
[KL] Double Bollinger Bands Strategy (for Crypto-FOREX) this page—v4 strategy−42.2%4256.8%
MCL-YG Pair Trading Strategy by shark792sma stdev atrv5 strategyNo trades on this market
[KL] Relative Volume + ATR Strategy by DojiEmojiatr sma stdevv4 strategy−32.7%1033.3%
[KL] Mean Reversion (ATR) Strategy by DojiEmojiatr sma stdevv5 strategyNo trades on this market
Fractal Breakout Strategy [KL] by DojiEmojisma atr stdevv5 strategy+1.9%360.8%
Mean Reversion Strategy v2 [KL] by DojiEmojiatr stdev smav5 strategy+1.7%521.5%

Where it runs

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

Zeal Terminal's engine currently merges fill() calls that share a title, so it would draw 1 of this script's 4 fills; this page gives each call its own title to draw all of them. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © DojiEmoji (kevinhhl)//@version=4strategy("[KL] Double BB Strategy",overlay=true,pyramiding=1)ENUM_LONG       = "LONG"LONG_MSG_ENTER  = input("Long +1 entered", type=input.string, title="Alert MSG for buying (Long position)")LONG_MSG_EXIT   = input("Long -1 closed", type=input.string, title="Alert MSG for closing (Long position)")ENUM_SHORT      = "SHORT"SHORT_MSG_ENTER = input("Short -1 entered", type=input.string, title="Alert MSG for selling (Short position)")SHORT_MSG_EXIT  = input("Short +1 covered", type=input.string, title="Alert MSG for covering (Short position)")// Timeframe {backtest_timeframe_start    = input(defval = timestamp("01 Apr 2020 13:30 +0000"), title = "Backtest Start Time", type = input.time)USE_ENDTIME                 = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")backtest_timeframe_end      = input(defval = timestamp("19 Apr 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)within_timeframe            = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)// } Timeframe// Bollinger bands {BOLL_length     = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length)BOLL_sDEV       = stdev(BOLL_src, BOLL_length)BOLL_upper1     = SMA20 + BOLL_sDEV, BOLL_lower1 = SMA20 - BOLL_sDEVBOLL_upper2     = SMA20 + BOLL_sDEV*2, BOLL_lower2 = SMA20 - BOLL_sDEV*2SMA_20_plot     = plot(SMA20, "Basis", color=#872323, offset = 0)BOLL_upper1_plot = plot(BOLL_upper1, "BOLL Upper1", color=color.new(color.navy, 50), offset = 0)BOLL_lower1_plot = plot(BOLL_lower1, "BOLL Lower1", color=color.new(color.navy, 50), offset = 0)BOLL_upper2_plot = plot(BOLL_upper2, "BOLL Upper2", color=color.new(color.navy, 50), offset = 0)BOLL_lower2_plot = plot(BOLL_lower2, "BOLL Lower2", color=color.new(color.navy, 50), offset = 0)fill(BOLL_upper2_plot, BOLL_upper1_plot, title = "Background", color=color.new(#198787, 85))fill(BOLL_upper1_plot, SMA_20_plot, title = "Background", color=color.new(#198787, 75))fill(SMA_20_plot, BOLL_lower1_plot, title = "Background", color=color.new(#198787, 75))fill(BOLL_lower1_plot, BOLL_lower2_plot, title = "Background", color=color.new(#198787, 85))// { Bollinger bands // Quantative methods - used for setting stop losses and entry/exit signals {cv = stdev(close,20)/sma(close,20)len_drift = input(14,title="lookback period for drift calc.")percentage_chng = log(close/close[1])drift = sma(percentage_chng, len_drift) - pow(stdev(percentage_chng, len_drift),2) * 0.5// } Quant methods// Trailing stop loss {ATR_X2_TSL = atr(input(14,title="Length of ATR for trailing stop loss")) * input(2.0,title="ATR Multiplier for trailing stop loss",type=input.float)TSL_source_long = low, TSL_source_short = highvar stop_loss_price_long    = float(0)var stop_loss_price_short = float(2147483647)var pos_opened_long = false // to be updated in MAIN loopvar pos_opened_short = false // to be updated in MAIN loopstop_loss_price_long := pos_opened_long ? max(stop_loss_price_long, TSL_source_long - ATR_X2_TSL) : TSL_source_long - ATR_X2_TSLstop_loss_price_short := pos_opened_short ? min(stop_loss_price_short, TSL_source_short + ATR_X2_TSL) : TSL_source_short + ATR_X2_TSL// tighten TSLis_consol = cv < sma(cv,50)TIGHTEN_TSL = input(true, title="Tighten stop loss when price moves sharply in favorable direction")if TIGHTEN_TSL    if not is_consol        if pos_opened_long and cv > cv[1]            stop_loss_price_long := max(stop_loss_price_long * (1+percentage_chng*0.5), stop_loss_price_long[1])        if pos_opened_short and cv > cv[1]            stop_loss_price_short := min(stop_loss_price_long * (1+percentage_chng*0.5), stop_loss_price_short[1])// Plot TSLTSL_transp_long = pos_opened_long and within_timeframe ? 0 : 100TSL_transp_short = pos_opened_short and within_timeframe ? 0 : 100plot(stop_loss_price_long, color=color.new(color.green, TSL_transp_long))plot(stop_loss_price_short, color=color.new(color.red, TSL_transp_short))// } Trailing stop loss// Signals for entry {is_neutral = close < BOLL_upper1 and close > BOLL_lower1below_neutral = close < BOLL_lower1 and close > BOLL_lower2above_neutral = close > BOLL_upper1 and close < BOLL_upper2atr14 = atr(14)entry_signal_long = is_consol and close > BOLL_upper1 and atr14 > sma(atr14,5) and drift > 0entry_signal_short = is_consol and close < BOLL_lower1 and atr14 > sma(atr14,5) and drift < 0// } Signals for entry// MAIN:if within_timeframe    // EXIT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::    if pos_opened_long        strategy.exit(ENUM_LONG, stop=stop_loss_price_long, comment="SL")    if pos_opened_short        strategy.exit(ENUM_SHORT, stop=stop_loss_price_short, comment="SL")        end_of_rally = close < BOLL_upper1 and strategy.position_avg_price > stop_loss_price_long and low < low[1]    if pos_opened_long and (TSL_source_long <= stop_loss_price_long or end_of_rally and not is_consol)        pos_opened_long := false        alert(LONG_MSG_EXIT, alert.freq_once_per_bar)        strategy.close(ENUM_LONG, comment=close < strategy.position_avg_price ? "stop loss" : "take profit")    if pos_opened_short and (TSL_source_short >= stop_loss_price_short)        pos_opened_short := false        alert(SHORT_MSG_EXIT, alert.freq_once_per_bar)        strategy.close(ENUM_SHORT, comment=close > strategy.position_avg_price ? "stop loss" : "take profit")    // ENTRY :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::    if entry_signal_long and close > stop_loss_price_long        pos_opened_long := true        alert(LONG_MSG_ENTER, alert.freq_once_per_bar)                strategy.entry(ENUM_LONG, strategy.long, comment="long")    if entry_signal_short        pos_opened_short := true        alert(SHORT_MSG_ENTER, alert.freq_once_per_bar)                strategy.entry(ENUM_SHORT, strategy.short, comment="short")// CLEAN UP:if not pos_opened_long    stop_loss_price_long := float(0)if not pos_opened_short    stop_loss_price_short := float(2147483647)