Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Chandelier + BB + EMAS

A Pine Script v4 strategy built on Highest or ATR (high, 22), Lowest or ATR (low, 22) and SMA (lenght). 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 is one contract and pays no commission. 13 settings; defaults include highest high o lowest low period 22, multiplicador 4 and moving averages period 50.

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 Chandelier + BB + EMAS repaint?
Yes
In a live replay, it did not match history on 2 of 2 trades, and it produced 2 trades that history does not have.
How did Chandelier + BB + EMAS do on BTCUSDT 1D with default settings?
−20.62%
From 26 Jan 2024 to 21 Oct 2026, over 10 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Chandelier + BB + EMAS 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 Chandelier + BB + EMAS use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Chandelier + BB + EMAS run in Zeal Terminal?
Yes
It compiles in 20 ms and runs 1,000 bars in 59 ms, in the browser.

BTCUSDT · 1D · default settings

  • Long Stop
  • Short Stop
  • Shape
  • Shape
  • 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 (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$79,387$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
−20.62%
−$20,616.40
Buy and hold
+102.5%
same period
Closed trades
10
3 won · 7 lost
Profitable
30.0%
of closed trades
Profit factor
0.63
gross profit ÷ gross loss
Max drawdown
38.63%
−$44,661.30

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No 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 63, 64, 65, 66. 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, atr → ta.atr, lowest → ta.lowest, sma → ta.sma, ema → ta.ema, stdev → ta.stdev, change → ta.change, crossover → ta.crossover, crossunder → ta.crossunder.
  • 4 strategy calls use the when = argument (line 63, 64, 65, 66). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 8: highest → ta.highest
  • Line 8: atr → ta.atr
  • Line 9: lowest → ta.lowest
  • Line 9: atr → ta.atr
  • Line 15: type is reserved in v5: renamed type_
8 more edits
  • Line 19: sma → ta.sma
  • Line 21: ema → ta.ema
  • Line 35: sma → ta.sma
  • Line 36: stdev → ta.stdev
  • Line 50: change → ta.change
  • Line 51: crossover → ta.crossover
  • Line 61: crossunder → ta.crossunder
  • Line 62: crossover → ta.crossover
⋯// © juanchez-//@version=4+//@version=5strategy("CHI", overlay = true, close_entries_rule = "ANY")⋯f= input(title= "multiplicador", defval= 4)-long = highest(high, n) - atr(n)*f+long = ta.highest(high, n) - ta.atr(n)*f-short= lowest(low, n) + atr(n)*f+short= ta.lowest(low, n) + ta.atr(n)*fplot(long, color= color.green, linewidth= 2, title= "Long Stop")⋯period2= input(title= "moving averages period2", defval= 20)-type= input(title= "moving averages type", options= ["sma", "ema"], defval= "ema")+type_= input(title= "moving averages type", options= ["sma", "ema"], defval= "ema")//moving average function⋯    if t == "sma"-        sma(close[barstate.islast ? 1: 0], p)+        ta.sma(close[barstate.islast ? 1: 0], p)    else  if t== "ema"-        ema(close[barstate.islast ? 1: 0], p)+        ta.ema(close[barstate.islast ? 1: 0], p)show= input(false, title= "Show EMAS")-m= mo(period, type)+m= mo(period, type_)-m2= mo(period2, type)+m2= mo(period2, type_)trend= m2 > m ⋯_bb(src, lenght, multi)=>-    float moving_avg= sma(src[barstate.islast? 1: 0], lenght)+    float moving_avg= ta.sma(src[barstate.islast? 1: 0], lenght)-    float deviation= stdev(src[barstate.islast? 1: 0], lenght)+    float deviation= ta.stdev(src[barstate.islast? 1: 0], lenght)    float lowerband = moving_avg - deviation*multi⋯widht= (upperband1 - lowerband1)/bb1-roc= change(widht)/widht[1]*100+roc= ta.change(widht)/widht[1]*100-cross=crossover(roc, thresh)+cross=ta.crossover(roc, thresh)// entry⋯plotshape(shortcondition? true: false , location= location.abovebar, style= shape.labeldown, size= size.small, color= color.red, text= "Sell", textcolor= color.white)-out= crossunder(close, long)+out= ta.crossunder(close, long)-outt= crossover(close, short)+outt= ta.crossover(close, short)strategy.entry("long", strategy.long, when = longcondition)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.string()
  • Line 22: input() → input.bool()
11 more edits
  • Line 29: input() → input.int()
  • Line 30: input() → input.source()
  • Line 31: input() → input.int()
  • Line 32: input() → input.bool()
  • Line 48: input() → input.int()
  • Line 54: input() → input.bool()
  • Line 57: input() → input.bool()
  • Line 63: when = longcondition → if block
  • Line 64: when = out → if block
  • Line 65: when = shortcondition → if block
  • Line 66: when = outt → if block
⋯//Chandelier-n = input(title= "highest high o lowest low period", defval= 22)+n = input.int(title= "highest high o lowest low period", defval= 22)-f= input(title= "multiplicador", defval= 4)+f= input.int(title= "multiplicador", defval= 4)long = ta.highest(high, n) - ta.atr(n)*f⋯//moving averages-period= input(title= "moving averages period", defval= 50)+period= input.int(title= "moving averages period", defval= 50)-period2= input(title= "moving averages period2", defval= 20)+period2= input.int(title= "moving averages period2", defval= 20)-type_= input(title= "moving averages type", options= ["sma", "ema"], defval= "ema")+type_= input.string(title= "moving averages type", options= ["sma", "ema"], defval= "ema")//moving average function⋯        ta.ema(close[barstate.islast ? 1: 0], p)-show= input(false, title= "Show EMAS")+show= input.bool(false, title= "Show EMAS")m= mo(period, type_)⋯//BOLLINGER BANDS ENTRIES-bb1_period= input(title= "Bollinger bands 1 period", defval=40, minval=1)+bb1_period= input.int(title= "Bollinger bands 1 period", defval=40, minval=1)-bb1_source=input(title="Bollinger band 1 source", defval=close)+bb1_source=input.source(title="Bollinger band 1 source", defval=close)-bb1_multi=input(title="Bollinger Bands 1 factor", defval=2, minval=1, step=0.1)+bb1_multi=input.int(title="Bollinger Bands 1 factor", defval=2, minval=1, step=0.1)-show_bb1= input(title="Show Bollinger bands 1", defval=false)+show_bb1= input.bool(title="Show Bollinger bands 1", defval=false)//BOLLINGER BANDS⋯//BB's Width threshold -thresh= input(title= "widen %", defval= 9, minval = 0, step = 1, maxval= 100)+thresh= input.int(title= "widen %", defval= 9, minval = 0, step = 1, maxval= 100)widht= (upperband1 - lowerband1)/bb1⋯//long-elong= input(true, title= "enable long")+elong= input.bool(true, title= "enable long")longcondition= m2 > m and cross and elong//short-eshort= input(true, title= "enable short")+eshort= input.bool(true, title= "enable short")shortcondition= m2 < m and cross and eshort⋯outt= ta.crossover(close, short)-strategy.entry("long", strategy.long, when = longcondition)+if longcondition+    strategy.entry("long", strategy.long)-strategy.close("long", when = out)+if out+    strategy.close("long")-strategy.entry("short", strategy.short, when = shortcondition)+if shortcondition+    strategy.entry("short", strategy.short)-strategy.close("short", when = outt)+if outt+    strategy.close("short")

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: 10 before, 13 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.

⋯// © juanchez-//@version=5+//@version=6strategy("CHI", overlay = true, close_entries_rule = "ANY")⋯

Settings

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

SettingDefaultType and rangeFeeds
highest high o lowest low period22intlong short
multiplicador4intlong short
moving averages period50intm
moving averages period220intm2
moving averages typeemastring · options ["sma", "ema"]m m2
Show EMASfalseboolSlow MA Fast MA
Bollinger bands 1 period40int · min 1bb1 lowerband1 upperband1
Bollinger band 1 sourceclosesourcebb1 lowerband1 upperband1
Bollinger Bands 1 factor2int · min 1 · step 0.1bb1 lowerband1 upperband1
Show Bollinger bands 1falseboolBB1 Moving average BB1 Upper Band BB1 Lower Band
widen %9int · min 0 · max 100 · step 1cross
enable longtrueboollongcondition
enable shorttrueboolshortcondition

What it calculates

  • Highest / ATR (highest, ta.highest in v5)high, highest high o lowest low period (22)long · line 8
  • Lowest / ATR (lowest, ta.lowest in v5)low, highest high o lowest low period (22)short · line 9
  • SMA (sma, ta.sma in v5)src[barstate.islast? 1: 0], lenghtmoving_avg · line 35
  • Stdev (stdev, ta.stdev in v5)src[barstate.islast? 1: 0], lenghtdeviation · line 36
  • Change (change, ta.change in v5)widhtroc · line 50
  • Crossover (crossover, ta.crossover in v5)roc, widen % (9)cross · line 51
  • Crossunder (crossunder, ta.crossunder in v5)close, longout · line 61
  • Crossover (crossover, ta.crossover in v5)close, shortoutt · 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.

highhighprice datanhighest high o lowest l…setting · 22fmultiplicadorsetting · 4lowlowprice datathreshwiden %setting · 9closecloseprice dataperiodmoving averages periodsetting · 50typemoving averages typesetting · emaperiod2moving averages period2setting · 20bb1_periodBollinger bands 1 periodsetting · 40bb1_multiBollinger Bands 1 factorsetting · 2longHighest / ATR→ longshortLowest / ATR→ shortmoving_avgSMA→ moving_avgdeviationStdev→ deviationrocChange→ roccrossCrossover→ crossoutCrossunder→ outouttCrossover→ outtmmvaluem2m2valuelowerband, upperbandlowerband · upperband2 valuesbb1, lowerband1, upperband1bb1 · lowerband1 +13 valueswidhtwidhtvaluelongconditionlongconditionconditionshortconditionshortconditionconditiontrendtrendconditionentry:longOpen longstrategy.entryclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.closeplot:10Long Stopplotplot:11Short Stopplotplot:26Slow MAplotplot:27Fast MAplotplot:44BB1 Moving averageplotplot:45BB1 Upper Bandplotplot:46BB1 Lower Bandplotplotshape:59plotshapeplotshapeplotshape:60plotshapeplotshape

Order rules

OrderFires whenBy defaultLine
Open long longlongconditionm2 > m and cross and elongOn63
Close longoutOn64
Open short shortshortconditionm2 < m and cross and eshortOn65
Close shortouttOn66

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

Does it repaint?

Yes

The live replay did not match history.

0/2trades 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−20.6%+102.5%1030%0.6338.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−4.8%+5.5%1118%0.8212.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+2.5%+9.8%1145%2.831.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%1030%1.630.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%729%0.190.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%757%2.450.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%956%1.350.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%1136%0.930.1%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 (highest high o lowest low period 22, multiplicador 4) made −8.2% before 26 Dec 2025 and −12.4% after it, against −12.4% for the defaults. 0% of the 48 combinations made money in-sample and 40% out-of-sample.

Before 26 Dec 2025 · in-sample
multiplicador ↓ · highest high o lowest low period →1113151922263137
2−37%−29%−36%−36%−35%−36%−41%−38%
3−24%−22%−22%−29%−29%−29%−29%−23%
4−10%−12%−9%−12%−8%−8%−26%−36%
5−64%−62%−39%−31%−19%−24%−23%−18%
6−73%−73%−73%−41%−36%−36%−27%−36%
7−75%−73%−73%−73%−73%−53%−53%−46%
From 26 Dec 2025 · out-of-sample
multiplicador ↓ · highest high o lowest low period →1113151922263137
2+22%+21%+22%+22%+22%+22%+33%+33%
3+10%+10%+10%+12%+12%+12%+29%+29%
40%+2%+2%+2%−12%−12%−11%−9%
50%0%0%0%0%−2%−2%−2%
60%0%0%0%0%0%0%−7%
70%0%0%0%0%0%0%0%

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 barsTradesWonP&L
Rising market10%−$3,137.06
Sideways market825%−$27,044.50
Falling market1100%$9,565.21

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

How bad could the drawdown be?

43.3%

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

0%50%
All 10 trades
SideEntryExitBarsP&L
short25 Jun 2024 60,293.3016 Jul 2024 64,724.1021−$4,430.76
long30 Oct 2024 72,736.4031 Dec 2024 92,792.1062$20,055.60
short26 Feb 2025 88,680.4023 Apr 2025 93,443.0056−$4,762.60
long11 Jul 2025 116,010.0020 Aug 2025 112,873.0040−$3,137.06
long26 Aug 2025 110,112.0030 Aug 2025 108,377.004−$1,734.58
short30 Aug 2025 108,377.003 Oct 2025 120,529.0034−$12,152.00
long4 Oct 2025 122,232.0012 Oct 2025 110,644.008−$11,587.80
short21 Nov 2025 86,637.2018 Apr 2026 77,072.00148$9,565.21
short2 Jun 2026 71,408.9022 Jul 2026 66,556.1050$4,852.75
short20 Aug 2026 69,334.8022 Sep 2026 86,620.0033−$17,285.20

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
Chandelier + BB + EMAS this page—v4 strategy−20.6%1038.6%
MA Bollinger Bands + RSI by LucasVivienstdev sma atr lowest highestv5 strategy−73.9%477.3%
Lawyers Trend Pro Strategy by ErdemDemirsma stdev lowest highestv4 strategy+12.1%10241.7%
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.3%
BTC Volatility Band Strategy by gary_tradessma stdev lowest highestv4 strategy−33.5%8045.0%
Trend Following with Donchian Channels and MACD by Robrecht99highest lowest sma atrv5 strategy−1.0%122.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 20 msWith a workaround 1,000 bars in 59 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/// © juanchez//@version=4strategy("CHI", overlay = true, close_entries_rule = "ANY")//Chandeliern = input(title= "highest high o lowest low period", defval= 22)f= input(title= "multiplicador", defval= 4)long = highest(high, n) - atr(n)*fshort= lowest(low, n) + atr(n)*fplot(long, color= color.green, linewidth= 2, title= "Long Stop")plot(short, color= color.red, linewidth= 2, title= "Short Stop")//moving averagesperiod= input(title= "moving averages period", defval= 50)period2= input(title= "moving averages period2", defval= 20)type= input(title= "moving averages type", options= ["sma", "ema"], defval= "ema")//moving average functionmo(p, t) =>    if t == "sma"        sma(close[barstate.islast ? 1: 0], p)    else  if t== "ema"        ema(close[barstate.islast ? 1: 0], p)show= input(false, title= "Show EMAS")m= mo(period, type)m2= mo(period2, type)trend= m2 > m plot(show?  m:na, title= "Slow MA", color = color.maroon, linewidth = 3)plot(show? m2: na, title= "Fast MA",linewidth= 3)//BOLLINGER BANDS ENTRIESbb1_period= input(title= "Bollinger bands 1 period", defval=40, minval=1)bb1_source=input(title="Bollinger band 1 source", defval=close)bb1_multi=input(title="Bollinger Bands 1 factor", defval=2, minval=1, step=0.1)show_bb1= input(title="Show Bollinger bands 1", defval=false)//BOLLINGER BANDS_bb(src, lenght, multi)=>    float moving_avg= sma(src[barstate.islast? 1: 0], lenght)    float deviation= stdev(src[barstate.islast? 1: 0], lenght)    float lowerband = moving_avg - deviation*multi    float upperband = moving_avg + deviation*multi        [moving_avg, lowerband, upperband]    [bb1, lowerband1, upperband1]= _bb(bb1_source,  bb1_period, bb1_multi)//FIRST BAND    plot(show_bb1? bb1 : na, title="BB1 Moving average", linewidth= 3, color= color.fuchsia)plot(show_bb1? upperband1 : na, title="BB1 Upper Band", linewidth= 3, color= color.green)plot(show_bb1? lowerband1 : na, title="BB1 Lower Band", linewidth= 3, color= color.red)//BB's Width threshold thresh= input(title= "widen %", defval= 9, minval = 0, step = 1, maxval= 100)widht= (upperband1 - lowerband1)/bb1roc= change(widht)/widht[1]*100cross=crossover(roc, thresh)// entry//longelong= input(true, title= "enable long")longcondition= m2 > m and cross and elong//shorteshort= input(true, title= "enable short")shortcondition= m2 < m and cross and eshortplotshape(longcondition? true: false , location= location.belowbar, style= shape.labelup, size= size.small, color= color.green, text= "Buy", textcolor= color.white)plotshape(shortcondition? true: false , location= location.abovebar, style= shape.labeldown, size= size.small, color= color.red, text= "Sell", textcolor= color.white)out= crossunder(close, long)outt= crossover(close, short)strategy.entry("long", strategy.long, when = longcondition)strategy.close("long", when = out)strategy.entry("short", strategy.short, when = shortcondition)strategy.close("short", when = outt)