Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Bollinger -B Candles Strategy

A Pine Script v4 strategy built on SMA or EMA or HMA or RMA or VWMA or WMA (source, length) and BB (close, 100). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 10% of equity and pays 0.01% commission. 14 settings; defaults include BBLength 100, Moving Average Type rma and Lookback Period 22.

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 Bollinger -B Candles Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did Bollinger -B Candles Strategy do on BTCUSDT 1D with default settings?
+17.30%
From 26 Jan 2024 to 21 Oct 2026, over 29 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Bollinger -B Candles 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 Bollinger -B Candles Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Bollinger -B Candles Strategy run in Zeal Terminal?
Yes
It compiles in 36 ms and runs 1,000 bars in 114 ms, in the browser.

BTCUSDT · 1D · default settings

  • TrailingStop
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctTrailingStop$11,688$20,253Equity from $10,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. The live re-run is not offered here: the script requests BINANCE:BTCUSDT 12M, which this page cannot load in your browser.
Net profit
+17.30%
$1,729.98
Buy and hold
+102.5%
same period
Closed trades
29
10 won · 19 lost
Profitable
34.5%
of closed trades
Profit factor
2.71
gross profit ÷ gross loss
Max drawdown
5.10%
−$570.85

One run with the author's default settings, $10,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.

  • Check

    No stop loss

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

  • Note

    11 settings have no label

    In the settings dialog BBLength (line 5), useMovingAverage (line 7), lookbackPeriod (line 9), colorByPreviousClose (line 10), delaySignalBars (line 11), AtrLength (line 13), AtrMult (line 14), wicks (line 15), considerYearlyHighLow (line 16), considerNewLongTermHighLows (line 17), backtestYears (line 21) show an empty name. The labels on this page come from the variable names.

  • 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 99, 100, 101, 102. The upgraded version below moves each call inside an if block.

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 highest → ta.highest, lowest → ta.lowest, security → request.security, max → math.max, min → math.min, sma → ta.sma, ema → ta.ema, hma → ta.hma, rma → ta.rma, vwma → ta.vwma, wma → ta.wma, bb → ta.bb.
  • 4 strategy calls use the when = argument (line 99, 100, 101, 102). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 24: highest → ta.highest
  • Line 24: highest → ta.highest
  • Line 25: lowest → ta.lowest
  • Line 25: lowest → ta.lowest
  • Line 29: security → request.security
25 more edits
  • Line 30: security → request.security
  • Line 36: max → math.max
  • Line 36: max → math.max
  • Line 36: min → math.min
  • Line 38: min → math.min
  • Line 38: min → math.min
  • Line 38: max → math.max
  • Line 44: sma → ta.sma
  • Line 46: ema → ta.ema
  • Line 48: hma → ta.hma
  • Line 50: rma → ta.rma
  • Line 52: vwma → ta.vwma
  • Line 54: wma → ta.wma
  • Line 59: bb → ta.bb
  • Line 60: bb → ta.bb
  • Line 61: bb → ta.bb
  • Line 62: bb → ta.bb
  • Line 75: max → math.max
  • Line 75: min → math.min
  • Line 80: max → math.max
  • Line 83: min → math.min
  • Line 93: lowest → ta.lowest
  • Line 94: highest → ta.highest
  • Line 95: highest → ta.highest
  • Line 96: lowest → ta.lowest
⋯// © HeWhoMustNotBeNamed-//@version=4+//@version=5strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)=>-    newHigh = highest(shortHighLowPeriod) == highest(longHighLowPeriod) or not considerNewLongTermHighLows+    newHigh = ta.highest(shortHighLowPeriod) == ta.highest(longHighLowPeriod) or not considerNewLongTermHighLows-    newLow = lowest(shortHighLowPeriod) == lowest(longHighLowPeriod) or not considerNewLongTermHighLows+    newLow = ta.lowest(shortHighLowPeriod) == ta.lowest(longHighLowPeriod) or not considerNewLongTermHighLows    [newHigh,newLow]⋯f_getYearlyHighLowCondition(considerYearlyHighLow)=>-    yhigh = security(syminfo.tickerid, '12M', high[1]) +    yhigh = request.security(syminfo.tickerid, '12M', high[1]) -    ylow = security(syminfo.tickerid, '12M', low[1]) +    ylow = request.security(syminfo.tickerid, '12M', low[1])     yhighlast = yhigh[365]⋯    -    yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > max(yhigh,yhighlast) : close > max(yhigh, min(yhighlast, yhighllast))+    yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > math.max(yhigh,yhighlast) : close > math.max(yhigh, math.min(yhighlast, yhighllast))    yearlyHighCondition = (  (na(yhigh) or na(yhighlast) ? true : (yhigh > yhighlast) ) and ( na(yhigh) or na(yhighllast) ? true : (yhigh > yhighllast))) or yearlyTrendUp or not considerYearlyHighLow-    yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < min(ylow,ylowlast) : close < min(ylow, max(ylowlast, ylowllast))+    yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < math.min(ylow,ylowlast) : close < math.min(ylow, math.max(ylowlast, ylowllast))    yearlyLowCondition = (  (na(ylow) or na(ylowlast) ? true : (ylow < ylowlast) ) and ( na(ylow) or na(ylowllast) ? true : (ylow < ylowllast))) or yearlyTrendDown or not considerYearlyHighLow⋯f_getMovingAverage(source, MAType, length)=>-    ma = sma(source, length)+    ma = ta.sma(source, length)    if(MAType == "ema")-        ma := ema(source,length)+        ma := ta.ema(source,length)    if(MAType == "hma")-        ma := hma(source,length)+        ma := ta.hma(source,length)    if(MAType == "rma")-        ma := rma(source,length)+        ma := ta.rma(source,length)    if(MAType == "vwma")-        ma := vwma(source,length)+        ma := ta.vwma(source,length)    if(MAType == "wma")-        ma := wma(source,length)+        ma := ta.wma(source,length)    ma⋯[newHighS,newLowS] = f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)-[middleclose, upperclose, lowerclose] = bb(close, BBLength, StdDev)+[middleclose, upperclose, lowerclose] = ta.bb(close, BBLength, StdDev)-[middleopen, upperopen, loweropen] = bb(open, BBLength, StdDev)+[middleopen, upperopen, loweropen] = ta.bb(open, BBLength, StdDev)-[middlehigh, upperhigh, lowerhigh] = bb(high, BBLength, StdDev)+[middlehigh, upperhigh, lowerhigh] = ta.bb(high, BBLength, StdDev)-[middlelow, upperlow, lowerlow] = bb(low, BBLength, StdDev)+[middlelow, upperlow, lowerlow] = ta.bb(low, BBLength, StdDev)percentBClose = (close - lowerclose)*100/(upperclose-lowerclose)⋯newLow = useMovingAverage? percentBMALow : percentBLow-truerange = max(newHigh, newClose[1]) - min(newLow, newClose[1])+truerange = math.max(newHigh, newClose[1]) - math.min(newLow, newClose[1])averagetruerange = f_getMovingAverage(truerange, AtrMAType, AtrLength)⋯longStopPrev = nz(longStop[1], longStop)-longStop := (wicks ? newLow[1] : newClose[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop+longStop := (wicks ? newLow[1] : newClose[1]) > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = newClose + atrshortStopPrev = nz(shortStop[1], shortStop)-shortStop := (wicks ? newHigh[1] : newClose[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+shortStop := (wicks ? newHigh[1] : newClose[1]) < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopdir = 1⋯plot(trailingStop, title="TrailingStop", style=plot.style_linebr, linewidth=1, color= dir == 1 ? color.green : color.red)-buyCondition = lowest(dir,delaySignalBars)==1 and yearlyHighCondition and newHighS+buyCondition = ta.lowest(dir,delaySignalBars)==1 and yearlyHighCondition and newHighS-exitBuyCondition = highest(dir,delaySignalBars) == -1+exitBuyCondition = ta.highest(dir,delaySignalBars) == -1-sellCondition = highest(dir,delaySignalBars) == -1 and yearlyLowCondition and newLowS+sellCondition = ta.highest(dir,delaySignalBars) == -1 and yearlyLowCondition and newLowS-exitSellCondition = lowest(dir,delaySignalBars) == 1+exitSellCondition = ta.lowest(dir,delaySignalBars) == 1strategy.risk.allow_entry_in(tradeDirection)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.int()
  • Line 7: input() → input.bool()
  • Line 8: input() → input.string()
  • Line 9: input() → input.int()
  • Line 10: input() → input.bool()
  • Line 11: input() → input.int()
11 more edits
  • Line 12: input() → input.string()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.bool()
  • Line 16: input() → input.bool()
  • Line 17: input() → input.bool()
  • Line 21: input() → input.int()
  • Line 99: when = buyCondition and inDateRange → if block
  • Line 100: when = exitBuyCondition → if block
  • Line 101: when = sellCondition and inDateRange → if block
  • Line 102: when = exitSellCondition → if block
⋯strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)-BBLength = input(100, minval=1, step=1)+BBLength = input.int(100, minval=1, step=1)StdDev = 10-useMovingAverage = input(true)+useMovingAverage = input.bool(true)-MAType = input(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+MAType = input.string(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-lookbackPeriod = input(22, minval=10, step=10)+lookbackPeriod = input.int(22, minval=10, step=10)-colorByPreviousClose = input(true)+colorByPreviousClose = input.bool(true)-delaySignalBars = input(2, minval=2)+delaySignalBars = input.int(2, minval=2)-AtrMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])+AtrMAType = input.string(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])-AtrLength = input(10)+AtrLength = input.int(10)-AtrMult = input(4)+AtrMult = input.int(4)-wicks = input(false)+wicks = input.bool(false)-considerYearlyHighLow = input(false)+considerYearlyHighLow = input.bool(false)-considerNewLongTermHighLows = input(false)+considerNewLongTermHighLows = input.bool(false)shortHighLowPeriod = 100⋯tradeDirection = input(title="Trade Direction", defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])-backtestYears = input(10, minval=1, step=1)+backtestYears = input.int(10, minval=1, step=1)//////////////////////////////////// Calculate new high low condition //////////////////////////////////////////////////⋯barcolor(buyCondition? color.lime : sellCondition ? color.orange : color.silver)-strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.none)+if buyCondition and inDateRange+    strategy.entry("Buy", strategy.long, oca_name="oca_buy", oca_type=strategy.oca.none)-strategy.close("Buy", when=exitBuyCondition)+if exitBuyCondition+    strategy.close("Buy")-strategy.entry("Sell", strategy.short, when=sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.none)+if sellCondition and inDateRange+    strategy.entry("Sell", strategy.short, oca_name="oca_sell", oca_type=strategy.oca.none)-strategy.close("Sell", when=exitSellCondition)+if exitSellCondition+    strategy.close("Sell")

Does it run in Pine Script v6?

Yes

Same 29 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © HeWhoMustNotBeNamed-//@version=5+//@version=6strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)⋯

Settings

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

SettingDefaultType and rangeFeeds
BBLength (no label in the script)100int · min 1 · step 1middleclose upperclose lowerclose middleopen upperopen loweropen middlehigh upperhigh lowerhigh middlelow upperlow lowerlow
Use Moving Average (no label in the script)trueboolnewHigh newLow newOpen newClose
Moving Average Typermastring · options ["ema", "sma", "hma", "rma", "vwma", "wma"]percentBMAClose percentBMAOpen percentBMAHigh percentBMALow line 45 line 47 line 49 line 51 line 53
Lookback Period (no label in the script)22int · min 10 · step 10percentBMAClose percentBMAOpen percentBMAHigh percentBMALow
Color By Previous Close (no label in the script)trueboolcandleColor
Delay Signal Bars (no label in the script)2int · min 2buyCondition exitBuyCondition sellCondition exitSellCondition
Moving Average Typehmastring · options ["ema", "sma", "hma", "rma", "vwma", "wma"]averagetruerange
ATR Length (no label in the script)10intaveragetruerange
ATR Mult (no label in the script)4intatr
Wicks (no label in the script)falseboollongStop shortStop dir
Consider Yearly High Low (no label in the script)falseboolyearlyHighCondition yearlyLowCondition
Consider New Long Term High Lows (no label in the script)falseboolnewHighS newLowS newHigh newLow
Trade Directionstrategy.direction.allvalue · options [strategy.direction.all, strategy.direction.long, strategy.direction.short]line 97
Backtest Years (no label in the script)10int · min 1 · step 1inDateRange

What it calculates

  • SMA / EMA / HMA / RMA / VWMA / WMA (sma, ta.sma in v5)source, lengthma · line 44
  • BB (bb, ta.bb in v5)close, BBLength (100), StdDevmiddleclose · line 59
  • BB (bb, ta.bb in v5)close, BBLength (100), StdDevupperclose · line 59
  • BB (bb, ta.bb in v5)close, BBLength (100), StdDevlowerclose · line 59
  • BB (bb, ta.bb in v5)open, BBLength (100), StdDevmiddleopen · line 60
  • BB (bb, ta.bb in v5)open, BBLength (100), StdDevupperopen · line 60
  • BB (bb, ta.bb in v5)open, BBLength (100), StdDevloweropen · line 60
  • BB (bb, ta.bb in v5)high, BBLength (100), StdDevmiddlehigh · line 61
  • BB (bb, ta.bb in v5)high, BBLength (100), StdDevupperhigh · line 61
  • BB (bb, ta.bb in v5)high, BBLength (100), StdDevlowerhigh · line 61
  • BB (bb, ta.bb in v5)low, BBLength (100), StdDevmiddlelow · line 62
  • BB (bb, ta.bb in v5)low, BBLength (100), StdDevupperlow · line 62
  • BB (bb, ta.bb in v5)low, BBLength (100), StdDevlowerlow · line 62

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 67 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Buy longbuyCondition and inDateRangeOn99
Close BuyexitBuyConditionhighest(dir,delaySignalBars) == -1On100
Open Sell shortsellCondition and inDateRangeOn101
Close SellexitSellConditionlowest(dir,delaySignalBars) == 1On102

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.

4/4trades 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 data2 security call(s), none with lookahead on.
  • 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+17.3%+102.5%2934%2.715.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.0%+5.5%3639%1.222.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+22.3%+9.8%3345%2.384.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.4%+8.4%3824%0.953.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+16.0%+16.7%4132%1.737.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.7%+21.5%3244%1.381.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+17.7%+148.3%3345%2.704.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.7%+17.1%3824%0.851.6%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT 12M (aggregated from Binance BTCUSDT 1M), fetched from Binance's public market data for each market.

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market520%−$141.46
Sideways market1839%$1,728.85
Falling market633%$142.71

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

How bad could the drawdown be?

5.1%

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

0%6%
All 29 trades
SideEntryExitBarsP&L
long28 Jan 2024 42,120.6013 Jun 2024 68,264.00137$620.35
short13 Jun 2024 68,264.0016 Jul 2024 64,724.1033$54.86
long16 Jul 2024 64,724.104 Aug 2024 60,698.0019−$66.60
short4 Aug 2024 60,698.0025 Aug 2024 64,157.0021−$60.67
long25 Aug 2024 64,157.002 Sep 2024 57,301.808−$112.90
short2 Sep 2024 57,301.8014 Sep 2024 60,498.0012−$58.41
long14 Sep 2024 60,498.0011 Oct 2024 60,326.4027−$3.15
short11 Oct 2024 60,326.4013 Oct 2024 63,206.202−$49.73
long13 Oct 2024 63,206.2010 Dec 2024 97,276.5058$556.17
short10 Dec 2024 97,276.5026 Mar 2025 87,392.90106$110.33
long26 Mar 2025 87,392.9030 Mar 2025 82,648.504−$59.87
short30 Mar 2025 82,648.505 Apr 2025 83,889.906−$16.64
long5 Apr 2025 83,889.908 Apr 2025 79,163.203−$61.70
short8 Apr 2025 79,163.2011 Apr 2025 79,607.303−$6.30
long11 Apr 2025 79,607.3019 Jun 2025 104,887.0069$344.13
short19 Jun 2025 104,887.0011 Jul 2025 116,010.0022−$118.89
long11 Jul 2025 116,010.002 Aug 2025 113,298.0022−$26.10
short2 Aug 2025 113,298.0012 Aug 2025 118,686.0010−$52.75
long12 Aug 2025 118,686.0020 Aug 2025 112,873.008−$54.05
short20 Aug 2025 112,873.0017 Sep 2025 116,789.0028−$38.17
long17 Sep 2025 116,789.0023 Sep 2025 112,651.006−$38.83
short23 Sep 2025 112,651.003 Oct 2025 120,529.0010−$76.18
long3 Oct 2025 120,529.0013 Oct 2025 114,959.0010−$50.05
short13 Oct 2025 114,959.006 Dec 2025 89,330.0054$239.11
long6 Dec 2025 89,330.0031 Jan 2026 84,260.5056−$62.49
short31 Jan 2026 84,260.5027 Feb 2026 67,485.2027$217.02
long27 Feb 2026 67,485.2028 May 2026 74,449.3090$114.60
short28 May 2026 74,449.306 Jul 2026 63,650.0039$162.87
long6 Jul 2026 63,650.009 Oct 2026 81,754.5095$324.14

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
Bollinger -B Candles Strategy this page—v4 strategy+17.3%295.1%
Ultra Moving Average Rating Trend Strategy by exlux99ema wma highest lowest sma rma vwma hmav5 strategy+2.8%52.4%
VCP pivot buy by perrycc007sma ema rma vwma wma lowest highestv4 strategydoes not run in Zeal Terminal
MACD Willy Strategy by PtGamblerrma sma ema highest lowest wmav5 strategyNo trades on this market
Multi Trend Cross Strategy Template by TradeAutomationema hma rma sma vwma wma highest lowestv5 strategy+33.0%37.3%
Multi MA Trend Following Strategy Template by TradeAutomationema hma rma sma vwma wma highest lowestv5 strategy+12.3%326.9%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 36 msWith a workaround 1,000 bars in 114 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/// © HeWhoMustNotBeNamed//@version=4strategy("Bollinger %B Candles Strategy", overlay=false, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)BBLength = input(100, minval=1, step=1)StdDev = 10useMovingAverage = input(true)MAType = input(title="Moving Average Type", defval="rma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])lookbackPeriod = input(22, minval=10, step=10)colorByPreviousClose = input(true)delaySignalBars = input(2, minval=2)AtrMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])AtrLength = input(10)AtrMult = input(4)wicks = input(false)considerYearlyHighLow = input(false)considerNewLongTermHighLows = input(false)shortHighLowPeriod = 100longHighLowPeriod = 200tradeDirection = input(title="Trade Direction", defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])backtestYears = input(10, minval=1, step=1)//////////////////////////////////// Calculate new high low condition //////////////////////////////////////////////////f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)=>    newHigh = highest(shortHighLowPeriod) == highest(longHighLowPeriod) or not considerNewLongTermHighLows    newLow = lowest(shortHighLowPeriod) == lowest(longHighLowPeriod) or not considerNewLongTermHighLows    [newHigh,newLow]//////////////////////////////////// Calculate Yearly High Low //////////////////////////////////////////////////f_getYearlyHighLowCondition(considerYearlyHighLow)=>    yhigh = security(syminfo.tickerid, '12M', high[1])     ylow = security(syminfo.tickerid, '12M', low[1])     yhighlast = yhigh[365]    ylowlast = ylow[365]    yhighllast = yhigh[2 * 365]    ylowllast = ylow[2 * 365]        yearlyTrendUp = na(yhigh)? true : na(yhighlast)? close > yhigh : na(yhighllast)? close > max(yhigh,yhighlast) : close > max(yhigh, min(yhighlast, yhighllast))    yearlyHighCondition = (  (na(yhigh) or na(yhighlast) ? true : (yhigh > yhighlast) ) and ( na(yhigh) or na(yhighllast) ? true : (yhigh > yhighllast))) or yearlyTrendUp or not considerYearlyHighLow    yearlyTrendDown = na(ylow)? true : na(ylowlast)? close < ylow : na(ylowllast)? close < min(ylow,ylowlast) : close < min(ylow, max(ylowlast, ylowllast))    yearlyLowCondition = (  (na(ylow) or na(ylowlast) ? true : (ylow < ylowlast) ) and ( na(ylow) or na(ylowllast) ? true : (ylow < ylowllast))) or yearlyTrendDown or not considerYearlyHighLow        label_x = time+(60*60*24*1000*1)    [yearlyHighCondition,yearlyLowCondition]f_getMovingAverage(source, MAType, length)=>    ma = sma(source, length)    if(MAType == "ema")        ma := ema(source,length)    if(MAType == "hma")        ma := hma(source,length)    if(MAType == "rma")        ma := rma(source,length)    if(MAType == "vwma")        ma := vwma(source,length)    if(MAType == "wma")        ma := wma(source,length)    mainDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)[yearlyHighCondition,yearlyLowCondition] = f_getYearlyHighLowCondition(considerYearlyHighLow)[newHighS,newLowS] = f_calculateNewHighLows(shortHighLowPeriod, longHighLowPeriod, considerNewLongTermHighLows)[middleclose, upperclose, lowerclose] = bb(close, BBLength, StdDev)[middleopen, upperopen, loweropen] = bb(open, BBLength, StdDev)[middlehigh, upperhigh, lowerhigh] = bb(high, BBLength, StdDev)[middlelow, upperlow, lowerlow] = bb(low, BBLength, StdDev)percentBClose = (close - lowerclose)*100/(upperclose-lowerclose)percentBOpen = (open - loweropen)*100/(upperopen-loweropen)percentBHigh = (high - lowerhigh)*100/(upperhigh-lowerhigh)percentBLow = (low - lowerlow)*100/(upperlow-lowerlow)percentBMAClose = f_getMovingAverage(percentBClose, MAType, lookbackPeriod)percentBMAOpen = f_getMovingAverage(percentBOpen, MAType, lookbackPeriod)percentBMAHigh = f_getMovingAverage(percentBHigh, MAType, lookbackPeriod)percentBMALow = f_getMovingAverage(percentBLow, MAType, lookbackPeriod)newOpen = useMovingAverage? percentBMAOpen : percentBOpennewClose = useMovingAverage? percentBMAClose : percentBClosenewHigh = useMovingAverage? percentBMAHigh : percentBHighnewLow = useMovingAverage? percentBMALow : percentBLowtruerange = max(newHigh, newClose[1]) - min(newLow, newClose[1])averagetruerange = f_getMovingAverage(truerange, AtrMAType, AtrLength)atr = averagetruerange * AtrMultlongStop = newClose - atrlongStopPrev = nz(longStop[1], longStop)longStop := (wicks ? newLow[1] : newClose[1]) > longStopPrev ? max(longStop, longStopPrev) : longStopshortStop = newClose + atrshortStopPrev = nz(shortStop[1], shortStop)shortStop := (wicks ? newHigh[1] : newClose[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStopdir = 1dir := nz(dir[1], dir)dir := dir == -1 and (wicks ? newHigh : newClose) > shortStopPrev ? 1 : dir == 1 and (wicks ? newLow : newClose) < longStopPrev ? -1 : dirtrailingStop = dir == 1? longStop : shortStopcandleColor = colorByPreviousClose ?                 (newClose[1] < newClose ? color.green : newClose[1] > newClose ? color.red : color.silver) :                  (newOpen < newClose ? color.green : newOpen > newClose ? color.red : color.silver)plotcandle(newOpen, newHigh, newLow, newClose, title='PercentBCandle', color = candleColor)plot(trailingStop, title="TrailingStop", style=plot.style_linebr, linewidth=1, color= dir == 1 ? color.green : color.red)buyCondition = lowest(dir,delaySignalBars)==1 and yearlyHighCondition and newHighSexitBuyCondition = highest(dir,delaySignalBars) == -1sellCondition = highest(dir,delaySignalBars) == -1 and yearlyLowCondition and newLowSexitSellCondition = lowest(dir,delaySignalBars) == 1strategy.risk.allow_entry_in(tradeDirection)barcolor(buyCondition? color.lime : sellCondition ? color.orange : color.silver)strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.none)strategy.close("Buy", when=exitBuyCondition)strategy.entry("Sell", strategy.short, when=sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.none)strategy.close("Sell", when=exitSellCondition)