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
- 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
VerifiedSame 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)⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| highest high o lowest low period | 22 | int | long short |
| multiplicador | 4 | int | long short |
| moving averages period | 50 | int | m |
| moving averages period2 | 20 | int | m2 |
| moving averages type | ema | string · options ["sma", "ema"] | m m2 |
| Show EMAS | false | bool | Slow MA Fast MA |
| Bollinger bands 1 period | 40 | int · min 1 | bb1 lowerband1 upperband1 |
| Bollinger band 1 source | close | source | bb1 lowerband1 upperband1 |
| Bollinger Bands 1 factor | 2 | int · min 1 · step 0.1 | bb1 lowerband1 upperband1 |
| Show Bollinger bands 1 | false | bool | BB1 Moving average BB1 Upper Band BB1 Lower Band |
| widen % | 9 | int · min 0 · max 100 · step 1 | cross |
| enable long | true | bool | longcondition |
| enable short | true | bool | shortcondition |
What it calculates
- Highest / ATR (
highest,ta.highestin v5)high, highest high o lowest low period (22)long · line 8 - Lowest / ATR (
lowest,ta.lowestin v5)low, highest high o lowest low period (22)short · line 9 - SMA (
sma,ta.smain v5)src[barstate.islast? 1: 0], lenghtmoving_avg · line 35 - Stdev (
stdev,ta.stdevin v5)src[barstate.islast? 1: 0], lenghtdeviation · line 36 - Change (
change,ta.changein v5)widhtroc · line 50 - Crossover (
crossover,ta.crossoverin v5)roc, widen % (9)cross · line 51 - Crossunder (
crossunder,ta.crossunderin v5)close, longout · line 61 - Crossover (
crossover,ta.crossoverin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longconditionm2 > m and cross and elong | On | 63 |
| Close long | out | On | 64 |
| Open short short | shortconditionm2 < m and cross and eshort | On | 65 |
| Close short | outt | On | 66 |
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.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −20.6% | +102.5% | 10 | 30% | 0.63 | 38.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −4.8% | +5.5% | 11 | 18% | 0.82 | 12.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +2.5% | +9.8% | 11 | 45% | 2.83 | 1.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.3% | +8.4% | 10 | 30% | 1.63 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 7 | 29% | 0.19 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 7 | 57% | 2.45 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.1% | +148.3% | 9 | 56% | 1.35 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 11 | 36% | 0.93 | 0.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.
| multiplicador ↓ · highest high o lowest low period → | 11 | 13 | 15 | 19 | 22 | 26 | 31 | 37 |
|---|---|---|---|---|---|---|---|---|
| 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% |
| multiplicador ↓ · highest high o lowest low period → | 11 | 13 | 15 | 19 | 22 | 26 | 31 | 37 |
|---|---|---|---|---|---|---|---|---|
| 2 | +22% | +21% | +22% | +22% | +22% | +22% | +33% | +33% |
| 3 | +10% | +10% | +10% | +12% | +12% | +12% | +29% | +29% |
| 4 | 0% | +2% | +2% | +2% | −12% | −12% | −11% | −9% |
| 5 | 0% | 0% | 0% | 0% | 0% | −2% | −2% | −2% |
| 6 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | −7% |
| 7 | 0% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 0% | −$3,137.06 |
| Sideways market | 8 | 25% | −$27,044.50 |
| Falling market | 1 | 100% | $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.
All 10 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 25 Jun 2024 60,293.30 | 16 Jul 2024 64,724.10 | 21 | −$4,430.76 |
| long | 30 Oct 2024 72,736.40 | 31 Dec 2024 92,792.10 | 62 | $20,055.60 |
| short | 26 Feb 2025 88,680.40 | 23 Apr 2025 93,443.00 | 56 | −$4,762.60 |
| long | 11 Jul 2025 116,010.00 | 20 Aug 2025 112,873.00 | 40 | −$3,137.06 |
| long | 26 Aug 2025 110,112.00 | 30 Aug 2025 108,377.00 | 4 | −$1,734.58 |
| short | 30 Aug 2025 108,377.00 | 3 Oct 2025 120,529.00 | 34 | −$12,152.00 |
| long | 4 Oct 2025 122,232.00 | 12 Oct 2025 110,644.00 | 8 | −$11,587.80 |
| short | 21 Nov 2025 86,637.20 | 18 Apr 2026 77,072.00 | 148 | $9,565.21 |
| short | 2 Jun 2026 71,408.90 | 22 Jul 2026 66,556.10 | 50 | $4,852.75 |
| short | 20 Aug 2026 69,334.80 | 22 Sep 2026 86,620.00 | 33 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Chandelier + BB + EMAS this page | — | v4 strategy | −20.6% | 10 | 38.6% |
| MA Bollinger Bands + RSI by LucasVivien | stdev sma atr lowest highest | v5 strategy | −73.9% | 4 | 77.3% |
| Lawyers Trend Pro Strategy by ErdemDemir | sma stdev lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
| DC Breakout Strategy - This is simplicity at its finest. by Robrecht99 | sma highest lowest atr | v5 strategy | +10.8% | 57 | 8.3% |
| BTC Volatility Band Strategy by gary_trades | sma stdev lowest highest | v4 strategy | −33.5% | 80 | 45.0% |
| Trend Following with Donchian Channels and MACD by Robrecht99 | highest lowest sma atr | v5 strategy | −1.0% | 12 | 2.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 20 ms | With a workaround 1,000 bars in 59 ms | Not measured |
| PineTS | No 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)