Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[KL] Bollinger Bands Consolidation Strategy

A Pine Script v4 strategy built on SMA (BOLL_src, BOLL_length), Stdev (BOLL_src, BOLL_length) and ATR (BOLL_length). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 11 settings; defaults include No. of candles to lookback when determining ATR is decreasing 1, Source of TSL low and Reward ratio for exit (if selected above) 3.

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] Bollinger Bands Consolidation Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did [KL] Bollinger Bands Consolidation Strategy do on BTCUSDT 1D with default settings?
+39.11%
From 26 Jan 2024 to 21 Oct 2026, over 33 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [KL] Bollinger Bands Consolidation 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.
What alerts does [KL] Bollinger Bands Consolidation Strategy have?
3
Stop loss limit raised; BOLL bands are squeezing; BOLL bands stopped squeezing.
Does [KL] Bollinger Bands Consolidation Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • Basis
  • BOLL Upper
  • BOLL Lower
  • SMA20 + ATR_x2
  • SMA20 - ATR_x2
  • ATR_x2
  • 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)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$141,173$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. 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
+39.11%
$39,106.80
Buy and hold
+102.5%
same period
Closed trades
33
13 won · 20 lost
Profitable
39.4%
of closed trades
Profit factor
1.44
gross profit ÷ gross loss
Max drawdown
19.64%
−$26,739.80

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

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

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

  • Note

    No slippage

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

  • Note

    Uses an argument v6 removed

    when = on line 135. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 16

    transp = on line 16, 17, 18, 23, 24. 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 sma → ta.sma, stdev → ta.stdev, atr → ta.atr, avg → math.avg, max → math.max, ema → ta.ema, abs → math.abs, rsi → ta.rsi.
  • 1 strategy call uses the when = argument (line 135). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 4: //@version=4 → //@version=5
  • Line 7: input(type = input.time) → input.time()
  • Line 9: input(type = input.time) → input.time()
  • Line 13: sma → ta.sma
  • Line 13: stdev → ta.stdev
  • Line 16: transp = 50 → color.new(color.navy, 50)
17 more edits
  • Line 17: transp = 50 → color.new(color.navy, 50)
  • Line 18: transp = 85 → color.new(#198787, 85)
  • Line 21: atr → ta.atr
  • Line 22: sma → ta.sma
  • Line 23: transp = 50 → color.new(color.gray, 50)
  • Line 24: transp = 50 → color.new(color.gray, 50)
  • Line 43: avg → math.avg
  • Line 49: max → math.max
  • Line 59: ema → ta.ema
  • Line 73: max → math.max
  • Line 73: abs → math.abs
  • Line 77: rsi → ta.rsi
  • Line 77: rsi → ta.rsi
  • Line 95: abs → math.abs
  • Line 95: abs → math.abs
  • Line 132: max → math.max
  • Line 134: max → math.max
⋯// -//@version=4+//@version=5strategy("[KL] BB Consolidation Strategy",overlay=true,pyramiding=1)// Timeframe {-backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)+backtest_timeframe_start = input.time(defval = timestamp("01 Apr 2016 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 (sdv=2, len=20) {-BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)+BOLL_length = 20, BOLL_src = close, SMA20 = ta.sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * ta.stdev(BOLL_src, BOLL_length)BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2plot(SMA20, "Basis", color=#872323, offset = 0)-BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)+BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.new(color.navy, 50), offset = 0)-BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)+BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.new(color.navy, 50), offset = 0)-fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)+fill(BOLL_p1, BOLL_p2, title = "Background", color=color.new(#198787, 85))// }// Volatility Indicators {-ATR_x2 = atr(BOLL_length) * 2 // multiplier aligns with BOLL+ATR_x2 = ta.atr(BOLL_length) * 2 // multiplier aligns with BOLL-avg_atr = sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))+avg_atr = ta.sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))-plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)+plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.new(color.gray, 50), offset = 0)-plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)+plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.new(color.gray, 50), offset = 0)plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)⋯    else if case == "middle of both"-        result := avg(low, close)+        result := math.avg(low, close)    ⋯else if strategy.position_size > 0-    stop_loss_price := max(stop_loss_price, get_TSL_src() - trailing_SL_buffer)+    stop_loss_price := math.max(stop_loss_price, get_TSL_src() - trailing_SL_buffer)if strategy.position_size > 0 and stop_loss_price > stop_loss_price[1]⋯    alert("BOLL bands stopped squeezing", alert.freq_once_per_bar)-ema_trend = ema(close, 20)+ema_trend = ta.ema(close, 20)VERBOSE = input(true, title="Show text descriptions of buy/sell orders")⋯IGNORE_EXIT_CONSOL = input(true,title="Ignore sell signals during consolidation (unless hitting stop loss)")-bearish_candle1 = (close - open)/(high - low) < -0.5 and high > max(close[1],open[1]) and abs(open-close) > BOLL_sDEV_x2/2+bearish_candle1 = (close - open)/(high - low) < -0.5 and high > math.max(close[1],open[1]) and math.abs(open-close) > BOLL_sDEV_x2/2gapped_down = high < low[1] and close < open⋯reward_met = close >= (entry_price + (REWARD_RATIO_EXIT * risk_value))-rsi10 = rsi(close, 10), rsi14 = rsi(close, 14)+rsi10 = ta.rsi(close, 10), rsi14 = ta.rsi(close, 14)overbought = rsi14 > 70 and rsi10 > rsi14⋯        entry_msg := concat(entry_msg, "green")-    else if abs(close-open)/abs(high-low) < 0.1 //"Doji"+    else if math.abs(close-open)/math.abs(high-low) < 0.1 //"Doji"        conf_count := conf_count + 1⋯        if TIGHTEN_TSL_BEARISH and is_bearish-            stop_loss_price := max(low-(low-stop_loss_price)*0.9,stop_loss_price)+            stop_loss_price := math.max(low-(low-stop_loss_price)*0.9,stop_loss_price)        else if overbought and not EXIT_OVERBOUGHT-            stop_loss_price := max(low-(low-stop_loss_price)*0.7,stop_loss_price)+            stop_loss_price := math.max(low-(low-stop_loss_price)*0.7,stop_loss_price)        strategy.close("Long", when=bExit, comment=exit_msg)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.bool()
  • Line 22: input() → input.int()
  • Line 31: input() → input.bool()
  • Line 34: input() → input.string()
  • Line 60: input() → input.bool()
  • Line 71: input() → input.int()
4 more edits
  • Line 72: input() → input.bool()
  • Line 79: input() → input.bool()
  • Line 80: input() → input.bool()
  • Line 135: when = bExit → if block
⋯backtest_timeframe_start = input.time(defval = timestamp("01 Apr 2016 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)")⋯ATR_x2 = ta.atr(BOLL_length) * 2 // multiplier aligns with BOLL-avg_atr = ta.sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))+avg_atr = ta.sma(ATR_x2, input.int(1,title="No. of candles to lookback when determining ATR is decreasing"))plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.new(color.gray, 50), offset = 0)⋯var risk_value = trailing_SL_buffer //declared separately; trailing_SL_buffer may be tightened subsequently-UPDATE_ATR_LEN = input(true, title="Update the size of stoploss after entry")+UPDATE_ATR_LEN = input.bool(true, title="Update the size of stoploss after entry")if UPDATE_ATR_LEN and strategy.position_size > 0 and close < open    trailing_SL_buffer := ATR_x2-TSL_source = input(title="Source of TSL", defval="low", options=["close","low","middle of both"])+TSL_source = input.string(title="Source of TSL", defval="low", options=["close","low","middle of both"])get_TSL_src() =>⋯ema_trend = ta.ema(close, 20)-VERBOSE = input(true, title="Show text descriptions of buy/sell orders")+VERBOSE = input.bool(true, title="Show text descriptions of buy/sell orders")concat(a, b) =>⋯// Sell setup - Long position {-REWARD_RATIO_EXIT = input(3, title="Reward ratio for exit (if selected above)")+REWARD_RATIO_EXIT = input.int(3, title="Reward ratio for exit (if selected above)")-IGNORE_EXIT_CONSOL = input(true,title="Ignore sell signals during consolidation (unless hitting stop loss)")+IGNORE_EXIT_CONSOL = input.bool(true,title="Ignore sell signals during consolidation (unless hitting stop loss)")bearish_candle1 = (close - open)/(high - low) < -0.5 and high > math.max(close[1],open[1]) and math.abs(open-close) > BOLL_sDEV_x2/2⋯overbought = rsi14 > 70 and rsi10 > rsi14-EXIT_OVERBOUGHT = input(false,title="Exit position when overbought")+EXIT_OVERBOUGHT = input.bool(false,title="Exit position when overbought")-TIGHTEN_TSL_BEARISH = input(true,title="Tighten TSL instead of exiting when candle is bearish")+TIGHTEN_TSL_BEARISH = input.bool(true,title="Tighten TSL instead of exiting when candle is bearish")// } end of Sell setup - Long position⋯            stop_loss_price := math.max(low-(low-stop_loss_price)*0.7,stop_loss_price)-        strategy.close("Long", when=bExit, comment=exit_msg)+        if bExit+            strategy.close("Long", comment=exit_msg)// plot TSL line⋯

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: 33 before, 32 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// -//@version=5+//@version=6strategy("[KL] BB Consolidation 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
Backtest Start Timetimestamp("01 Apr 2016 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
No. of candles to lookback when determining ATR is decreasing1intline 90
Update the size of stoploss after entrytrueboolline 32
Source of TSLlowstring · options ["close","low","middle of both"]case
Show text descriptions of buy/sell orderstrueboolline 63
Reward ratio for exit (if selected above)3intreward_met
Ignore sell signals during consolidation (unless hitting stop loss)trueboolline 120
Exit position when overboughtfalseboolbExit line 133
Tighten TSL instead of exiting when candle is bearishtrueboolline 120 line 131

What it calculates

  • SMA (sma, ta.sma in v5)BOLL_src, BOLL_lengthSMA20 · line 13
  • Stdev (stdev, ta.stdev in v5)BOLL_src, BOLL_lengthBOLL_sDEV_x2 · line 13
  • ATR (atr, ta.atr in v5)BOLL_lengthATR_x2 · line 21
  • EMA (ema, ta.ema in v5)close, 20ema_trend · line 59
  • RSI (rsi, ta.rsi in v5)close, 10rsi10 · line 77
  • RSI (rsi, ta.rsi in v5)close, 14rsi14 · line 77

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.

high · low · closehigh · low · closeprice dataclosecloseprice datalowlowprice dataTSL_sourceSource of TSLsetting · lowtimetimeprice databacktest_timeframe_startBacktest Start Timesetting · timestamp("01 Apr 2…backtest_timeframe_endBacktest End Time (if c…setting · timestamp("19 Apr 2…highhighprice dataopenopenprice dataREWARD_RATIO_EXITReward ratio for exit (…setting · 3SMA20SMA→ SMA20BOLL_sDEV_x2Stdev→ BOLL_sDEV_x2ATR_x2ATR→ ATR_x2ema_trendEMA→ ema_trendrsi10RSI→ rsi10rsi14RSI→ rsi14BOLL_src, entry_priceBOLL_src · entry_price2 valuesBOLL_upper, BOLL_lowerBOLL_upper · BOLL_lower2 valuesstop_loss_pricestop_loss_pricevaluetrailing_SL_buffertrailing_SL_buffervaluerisk_valuerisk_valuevalueresultresultvaluecasecasevalueconcatconcatvalueentry_msgentry_msgvalueexit_msgexit_msgvalueconf_countconf_countvaluebExitbExitvalueis_squeezingis_squeezingconditionconfirm_entryconfirm_entryconditionwithin_timeframewithin_timeframeconditionbearish_candle1bearish_candle1conditiongapped_downgapped_downconditionis_bearishis_bearishconditionreward_metreward_metconditionoverboughtoverboughtconditionSL_hitSL_hitconditiontrail_profit_line_colorColourtrail_profit_line_colorentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:15Basisplotplot:16BOLL Upperplotplot:17BOLL Lowerplotfill:BackgroundBackgroundfillplot:23SMA20 + ATR_x2plotplot:24SMA20 - ATR_x2plotplotchar:25plotcharplotcharalert:51alertalertalert:56alertalertalert:58alertalertplot:137plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longis_squeezing and confirm_entry and strategy.position_size == 0On104
Close LongbExitOn135

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

Alerts

AlertCallMessageLine
(no title)alertStop loss limit raised51
(no title)alertBOLL bands are squeezing56
(no title)alertBOLL bands stopped squeezing58

Does it repaint?

No

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

6/6trades 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+39.1%+102.5%3339%1.4419.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−9.3%+5.5%4134%0.7217.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.4%+9.8%3625%0.783.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.2%+8.4%3435%0.860.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%3345%0.930.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3231%1.260.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%2836%0.990.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%3735%0.780.1%8 May 2026 – 21 Oct 2026

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1436%$10,482.10
Sideways market1346%$38,732.10
Falling market633%−$10,107.40

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

How bad could the drawdown be?

35.8%

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

0%41%
All 33 trades
SideEntryExitBarsP&L
long21 Mar 2024 67,840.5014 Apr 2024 63,924.5024−$3,915.99
long17 Apr 2024 63,793.402 May 2024 58,365.0015−$5,428.43
long3 May 2024 59,060.6015 Jun 2024 66,044.0043$6,983.39
long16 Jun 2024 66,228.3025 Jun 2024 60,293.309−$5,934.95
long14 Jul 2024 59,204.003 Aug 2024 61,498.3020$2,294.33
long20 Aug 2024 59,438.5028 Aug 2024 59,415.008−$23.50
long30 Aug 2024 59,359.007 Sep 2024 53,963.008−$5,396.03
long14 Sep 2024 60,498.002 Oct 2024 60,804.9018$306.93
long4 Oct 2024 60,752.704 Nov 2024 68,776.0031$8,023.27
long6 Nov 2024 69,372.0012 Nov 2024 88,648.006$19,276.00
long5 Dec 2024 98,587.3020 Dec 2024 97,461.9015−$1,125.46
long24 Dec 2024 94,881.5014 Jan 2025 94,536.1021−$345.36
long15 Jan 2025 96,560.904 Feb 2025 101,329.0020$4,767.66
long7 Feb 2025 96,554.4026 Feb 2025 88,680.4019−$7,873.96
long15 Mar 2025 83,983.207 Apr 2025 78,430.0023−$5,553.19
long12 Apr 2025 83,423.8022 May 2025 109,644.0040$26,220.20
long29 May 2025 107,782.006 Jun 2025 101,509.008−$6,273.09
long8 Jun 2025 105,552.0021 Jun 2025 103,298.0013−$2,254.17
long24 Jun 2025 105,334.0016 Jul 2025 117,758.0022$12,424.10
long28 Jul 2025 119,416.003 Aug 2025 112,546.006−$6,869.21
long5 Aug 2025 115,055.0020 Aug 2025 112,873.0015−$2,182.08
long21 Aug 2025 114,271.0030 Aug 2025 108,377.009−$5,893.83
long8 Sep 2025 111,137.0026 Sep 2025 108,994.0018−$2,142.86
long27 Sep 2025 109,643.007 Oct 2025 124,659.0010$15,015.10
long1 Nov 2025 109,608.005 Nov 2025 101,497.004−$8,110.78
long4 Dec 2025 93,429.9019 Dec 2025 85,516.4015−$7,913.54
long21 Dec 2025 88,360.9021 Jan 2026 88,427.7031$66.75
long23 Jan 2026 89,559.7030 Jan 2026 84,650.207−$4,909.52
long3 Mar 2026 68,830.1028 Mar 2026 66,407.3025−$2,422.78
long29 Mar 2026 66,377.0019 May 2026 77,001.9051$10,624.80
long21 May 2026 77,552.2029 May 2026 73,617.508−$3,934.72
long28 Jun 2026 60,029.0022 Aug 2026 78,338.0055$18,309.00
long9 Sep 2026 78,455.809 Oct 2026 81,754.5030$3,298.66

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] Bollinger Bands Consolidation Strategy this page—v4 strategy+39.1%3319.6%
[KL] Bollinger bands + RSI Strategy by DojiEmojisma stdev atr ema rsiv4 strategy+28.2%3014.7%
Full strategy AllinOne with risk management MACD RSI PSAR ATR MA by SoftKill21rsi sma stdev ema atrv4 strategy+2,985,110.0%32,350,820.0%
3 x EMA + Stochastic RSI + ATR by tomimarsonema rsi sma atrv4 strategy−42.3%1844.8%
Take Profit On Trend (by BHD_Trade_Bot) by BHD_Trade_Botema rsi stdev smav4 strategy+54.8%913.1%
Atrend by OTS by prim722ema rsi sma atrv4 strategy+12.1%7634.4%

Where it runs

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

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// //@version=4strategy("[KL] BB Consolidation Strategy",overlay=true,pyramiding=1)// Timeframe {backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 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)// }// Bollinger bands (sdv=2, len=20) {BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2plot(SMA20, "Basis", color=#872323, offset = 0)BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)// }// Volatility Indicators {ATR_x2 = atr(BOLL_length) * 2 // multiplier aligns with BOLLavg_atr = sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)//}// Trailing stop loss {var entry_price = float(0), var stop_loss_price = float(0), trail_profit_line_color = color.greenvar trailing_SL_buffer = float(0)var risk_value = trailing_SL_buffer //declared separately; trailing_SL_buffer may be tightened subsequentlyUPDATE_ATR_LEN = input(true, title="Update the size of stoploss after entry")if UPDATE_ATR_LEN and strategy.position_size > 0 and close < open    trailing_SL_buffer := ATR_x2TSL_source = input(title="Source of TSL", defval="low", options=["close","low","middle of both"])get_TSL_src() =>    result = float(-1)    case = TSL_source    if case == "close"        result := close    else if case == "low"        result := low    else if case == "middle of both"        result := avg(low, close)    if strategy.position_size == 0 or not within_timeframe    trail_profit_line_color := color.black          // make TSL line less visible    stop_loss_price := get_TSL_src() - ATR_x2       //  "   else if strategy.position_size > 0    stop_loss_price := max(stop_loss_price, get_TSL_src() - trailing_SL_buffer)if strategy.position_size > 0 and stop_loss_price > stop_loss_price[1]    alert("Stop loss limit raised", alert.freq_once_per_bar)// } end of Trailing stop loss//Buy setup - Long positions {is_squeezing = ATR_x2 > BOLL_sDEV_x2if is_squeezing and within_timeframe and not is_squeezing[1]    alert("BOLL bands are squeezing", alert.freq_once_per_bar)else if not is_squeezing and within_timeframe and is_squeezing[1]    alert("BOLL bands stopped squeezing", alert.freq_once_per_bar)ema_trend = ema(close, 20)VERBOSE = input(true, title="Show text descriptions of buy/sell orders")concat(a, b) =>    concat = " "    if VERBOSE        concat := a        if a != ""            concat := concat + ", "        concat := concat + b    concat// } end of Buy setup - Long positions// Sell setup - Long position {REWARD_RATIO_EXIT = input(3, title="Reward ratio for exit (if selected above)")IGNORE_EXIT_CONSOL = input(true,title="Ignore sell signals during consolidation (unless hitting stop loss)")bearish_candle1 = (close - open)/(high - low) < -0.5 and high > max(close[1],open[1]) and abs(open-close) > BOLL_sDEV_x2/2gapped_down = high < low[1] and close < openis_bearish = bearish_candle1 or gapped_downreward_met = close >= (entry_price + (REWARD_RATIO_EXIT * risk_value))rsi10 = rsi(close, 10), rsi14 = rsi(close, 14)overbought = rsi14 > 70 and rsi10 > rsi14EXIT_OVERBOUGHT = input(false,title="Exit position when overbought")TIGHTEN_TSL_BEARISH = input(true,title="Tighten TSL instead of exiting when candle is bearish")// } end of Sell setup - Long position// MAIN:if within_timeframe    entry_msg = ""    exit_msg = ""    // ENTRY    confirm_entry = false    conf_count = 0        if avg_atr <= avg_atr[1] // "decreased volatility"        conf_count := conf_count + 1    if open < close // "Green candlestick"        conf_count := conf_count + 1        entry_msg := concat(entry_msg, "green")    else if abs(close-open)/abs(high-low) < 0.1 //"Doji"        conf_count := conf_count + 1        entry_msg := concat(entry_msg, "doji")    if ema_trend > ema_trend[1] //"Upward EMA20"        conf_count := conf_count + 1        entry_msg := concat(entry_msg, "+ve ema20")    confirm_entry := conf_count >= 2        if is_squeezing and confirm_entry and strategy.position_size == 0        strategy.entry("Long",strategy.long, comment=entry_msg)        entry_price := close        trailing_SL_buffer := ATR_x2        risk_value := trailing_SL_buffer // may be adjusted during holding-period        stop_loss_price := get_TSL_src() - trailing_SL_buffer            // EXIT    if strategy.position_size > 0        SL_hit = low < stop_loss_price        bExit = false        if close > entry_price and SL_hit            exit_msg := concat(exit_msg, "profit [TSL]")            bExit := true        else if close <= entry_price and SL_hit            exit_msg := concat(exit_msg, "stop loss")            bExit := true        else if (not IGNORE_EXIT_CONSOL or not is_squeezing) and is_bearish and not TIGHTEN_TSL_BEARISH            exit_msg := concat(exit_msg, "bearish")            bExit := true                if reward_met            exit_msg := concat(exit_msg, "reward met")            bExit := true        else if overbought            exit_msg := concat(exit_msg, "overbought")            bExit := EXIT_OVERBOUGHT                if TIGHTEN_TSL_BEARISH and is_bearish            stop_loss_price := max(low-(low-stop_loss_price)*0.9,stop_loss_price)        else if overbought and not EXIT_OVERBOUGHT            stop_loss_price := max(low-(low-stop_loss_price)*0.7,stop_loss_price)        strategy.close("Long", when=bExit, comment=exit_msg)// plot TSL lineplot(stop_loss_price, color=trail_profit_line_color)// CLEAN UP:if strategy.position_size == 0 and not is_squeezing    entry_price := 0    trailing_SL_buffer := float(0)    stop_loss_price := float(0)    risk_value := 0