Pine Script v5 · Strategy
Chandelier Exit ZLSMA Strategy
A Pine Script v5 strategy built on ATR (1), Highest (haClose, 1) and Lowest (haClose, 1). 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.075 commission. 8 settings; defaults include ATR Period 1, ATR Multiplier 2 and ZLSMA Length 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 Exit ZLSMA Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did Chandelier Exit ZLSMA Strategy do on BTCUSDT 1D with default settings?
- +2.38%
- From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Chandelier Exit ZLSMA Strategy 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: 8 before, 12 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Chandelier Exit ZLSMA Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Chandelier Exit ZLSMA Strategy run in Zeal Terminal?
- Yes
- It compiles in 45 ms and runs 1,000 bars in 67 ms, in the browser.
BTCUSDT · 1D · default settings
- ZLSMA
- LONG
- SHORT
- LONG EXIT
- SHORT EXIT
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2.38%
- $23.79
- Buy and hold
- +102.5%
- same period
- Closed trades
- 8
- 4 won · 4 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 1.98
- gross profit ÷ gross loss
- Max drawdown
- 2.15%
- −$21.94
One run with the author's default settings, $1,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.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 |
|---|---|---|---|
| ATR Period | 1 | int | atr longStop shortStop |
| ATR Multiplier | 2 | float · step 0.1 | atr |
| Show Buy/Sell Labels ?Created by Chandelier Exit (CE) | false | bool | Buy Label Sell Label |
| Show Signal Labels ? | true | bool | LONG SHORT LONG EXIT SHORT EXIT |
| Use Close Price for Extrema ? | true | bool | longStop shortStop |
| Enable Rising/Decreasing Highlightning | false | bool | zColor |
| ZLSMA Length | 50 | int | lsma lsma2 |
| Offset | 0 | int | lsma lsma2 |
What it calculates
- ATRATR Period (1)
atr · line 27 - HighesthaClose, ATR Period (1)
longStop · line 28 - LowesthaClose, ATR Period (1)
shortStop · line 31 - LinreghaClose, ZLSMA Length (50), Offset (0)
lsma · line 42 - Linreglsma, ZLSMA Length (50), Offset (0)
lsma2 · line 43 - CrossunderhaClose, zlsma
exitLong · line 52 - CrossoverhaClose, zlsma
exitShort · line 54
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 |
|---|---|---|---|
| Close long | (exitLong and strategy.position_size > 0) | On | 103 |
| Close short | (exitShort and strategy.position_size < 0) | On | 106 |
| Open long long | (enterLong) | On | 109 |
| Open short short | (enterShort) | On | 112 |
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.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +2.4% | +102.5% | 8 | 50% | 1.98 | 2.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.7% | +5.5% | 9 | 22% | 0.33 | 1.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.4% | +9.8% | 14 | 57% | 1.28 | 4.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.7% | +8.4% | 13 | 31% | 0.30 | 2.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +2.4% | +16.7% | 3 | 67% | 2.71 | 1.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +2.0% | +21.5% | 6 | 100% | — | 0.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.3% | +148.3% | 8 | 50% | 0.80 | 2.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.3% | +17.1% | 9 | 44% | 1.82 | 0.5% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 100% | $21.39 |
| Sideways market | 5 | 40% | −$9.00 |
| Falling market | 2 | 50% | $11.40 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2.4%
The 95th percentile of the worst drawdown when the same 8 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.0% to 2.4%; the tick is what actually happened, 1.8%. Order luck alone moves it this much.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Oct 2024 72,736.40 | 3 Nov 2024 68,776.00 | 5 | −$5.59 |
| long | 7 Nov 2024 75,857.90 | 19 Nov 2024 92,310.80 | 12 | $21.39 |
| long | 22 Apr 2025 93,443.00 | 1 May 2025 96,489.90 | 9 | $3.16 |
| long | 11 Aug 2025 118,686.00 | 20 Aug 2025 114,271.00 | 9 | −$3.94 |
| short | 21 Aug 2025 112,500.00 | 22 Aug 2025 116,936.00 | 1 | −$4.15 |
| short | 16 Dec 2025 87,863.40 | 14 Jan 2026 96,951.80 | 29 | −$10.61 |
| short | 20 Jan 2026 88,427.70 | 10 Feb 2026 68,841.30 | 21 | $22.01 |
| long | 3 May 2026 78,568.60 | 4 May 2026 79,861.00 | 1 | $1.53 |
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 Exit ZLSMA Strategy this page | — | v5 strategy | +2.4% | 8 | 2.2% |
| Aggresive Scalper-Swing Crypto Strategy by exlux99 | lowest highest atr | v4 strategy | −7.4% | 3 | 16.0% |
| Donchian Channels Strategy by KrisWaters by kriswaters | highest lowest atr | v4 strategy | +55.8% | 21 | 23.3% |
| Chandelier Exit - Strategy by melihtuna | atr highest lowest | v4 strategy | −34.8% | 11 | 43.2% |
| ETF trader by FX_minds | atr lowest highest | v4 strategy | +78.3% | 17 | 32.7% |
| Chandelier Exit by Zeal Terminal | atr highest lowest | v5 indicator | indicator | ||
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 7 settings use the untyped input() (line 17, 19, 20, 21, 22, 23, 24). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 17: input() → input.int()
- Line 19: input() → input.bool()
- Line 20: input() → input.bool()
- Line 21: input() → input.bool()
- Line 22: input() → input.bool()
- Line 23: input() → input.int()
- Line 24: input() → input.int()
⋯// -- Inputs ---length = input(title='ATR Period', defval=1)+length = input.int(title='ATR Period', defval=1)mult = input.float(title='ATR Multiplier', step=0.1, defval=2)-showLabels = input(title='Show Buy/Sell Labels ?', tooltip='Created by Chandelier Exit (CE)', defval=false)+showLabels = input.bool(title='Show Buy/Sell Labels ?', tooltip='Created by Chandelier Exit (CE)', defval=false)-isSignalLabelEnabled = input(title='Show Signal Labels ?', defval=true)+isSignalLabelEnabled = input.bool(title='Show Signal Labels ?', defval=true)-useClose = input(title='Use Close Price for Extrema ?', defval=true)+useClose = input.bool(title='Use Close Price for Extrema ?', defval=true)-zcolorchange = input(title='Enable Rising/Decreasing Highlightning', defval=false)+zcolorchange = input.bool(title='Enable Rising/Decreasing Highlightning', defval=false)-zlsmaLength = input(title='ZLSMA Length', defval=50)+zlsmaLength = input.int(title='ZLSMA Length', defval=50)-offset = input(title='Offset', defval=0)+offset = input.int(title='Offset', defval=0)// -- CE - Credits to @everget --⋯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: 8 before, 12 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=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 45 ms | Yes 1,000 bars in 67 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © simwaistrategy('Chandelier Exit ZLSMA Strategy', shorttitle='CE_ZLSMA', overlay = true, initial_capital = 1000, default_qty_value = 10, default_qty_type = strategy.percent_of_equity, calc_on_every_tick = false, process_orders_on_close = true, commission_value = 0.075)// -- Colors --color maximumYellowRed = color.rgb(255, 203, 98) // yellowcolor rajah = color.rgb(242, 166, 84) // orangecolor magicMint = color.rgb(171, 237, 198)color languidLavender = color.rgb(232, 215, 255)color maximumBluePurple = color.rgb(181, 161, 226)color skyBlue = color.rgb(144, 226, 244)color lightGray = color.rgb(214, 214, 214)color quickSilver = color.rgb(163, 163, 163)color mediumAquamarine = color.rgb(104, 223, 153)color carrotOrange = color.rgb(239, 146, 46)// -- Inputs --length = input(title='ATR Period', defval=1)mult = input.float(title='ATR Multiplier', step=0.1, defval=2)showLabels = input(title='Show Buy/Sell Labels ?', tooltip='Created by Chandelier Exit (CE)', defval=false)isSignalLabelEnabled = input(title='Show Signal Labels ?', defval=true)useClose = input(title='Use Close Price for Extrema ?', defval=true)zcolorchange = input(title='Enable Rising/Decreasing Highlightning', defval=false)zlsmaLength = input(title='ZLSMA Length', defval=50)offset = input(title='Offset', defval=0)// -- CE - Credits to @everget --float haClose = float(1) / 4 * (open[1] + high[1] + low[1] + close[1])atr = mult * ta.atr(length)[1]longStop = (useClose ? ta.highest(haClose, length) : ta.highest(haClose, length)) - atrlongStopPrev = nz(longStop[1], longStop)longStop := haClose > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = (useClose ? ta.lowest(haClose, length) : ta.lowest(haClose, length)) + atrshortStopPrev = nz(shortStop[1], shortStop)shortStop := haClose < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopvar int dir = 1dir := haClose > shortStopPrev ? 1 : haClose < longStopPrev ? -1 : dirbuySignal = dir == 1 and dir[1] == -1plotshape(buySignal and showLabels ? longStop : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=mediumAquamarine, textcolor=color.white)sellSignal = dir == -1 and dir[1] == 1plotshape(sellSignal and showLabels ? shortStop : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=carrotOrange, textcolor=color.white)changeCond = dir != dir[1]// -- ZLSMA - Credits to @netweaver2011 --lsma = ta.linreg(haClose, zlsmaLength, offset)lsma2 = ta.linreg(lsma, zlsmaLength, offset)eq = lsma - lsma2zlsma = lsma + eqzColor = zcolorchange ? zlsma > zlsma[1] ? magicMint : rajah : languidLavenderplot(zlsma, title='ZLSMA', linewidth=2, color=zColor)// -- Signals --var string isTradeOpen = ''var string signalCache = ''bool enterLong = buySignal and ta.crossover(haClose, zlsma) bool exitLong = ta.crossunder(haClose, zlsma) bool enterShort = sellSignal and ta.crossunder(haClose, zlsma)bool exitShort = ta.crossover(haClose, zlsma)if (signalCache == 'long entry') signalCache := '' enterLong := trueelse if (signalCache == 'short entry') signalCache := '' enterShort := trueif (isTradeOpen == '') if (exitShort and (not enterLong)) exitShort := false if (exitLong and (not enterShort)) exitLong := false if (enterLong and exitShort) isTradeOpen := 'long' exitShort := false else if (enterShort and exitLong) isTradeOpen := 'short' exitLong := false else if (enterLong) isTradeOpen := 'long' else if (enterShort) isTradeOpen := 'short'else if (isTradeOpen == 'long') if (exitShort) exitShort := false if (enterLong) enterLong := false if (enterShort and exitLong) enterShort := false signalCache := 'short entry' if (exitLong) isTradeOpen := ''else if (isTradeOpen == 'short') if (exitLong) exitLong := false if (enterShort) enterShort := false if (enterLong and exitShort) enterLong := false signalCache := 'long entry' if (exitShort) isTradeOpen := ''plotshape((isSignalLabelEnabled and enterLong) ? zlsma : na, title='LONG', text='L', style=shape.labelup, color=mediumAquamarine, textcolor=color.white, size=size.tiny, location=location.absolute)plotshape((isSignalLabelEnabled and enterShort) ? zlsma : na, title='SHORT', text='S', style=shape.labeldown, color=carrotOrange, textcolor=color.white, size=size.tiny, location=location.absolute)plotshape((isSignalLabelEnabled and exitLong) ? zlsma : na, title='LONG EXIT', style=shape.circle, color=magicMint, size=size.tiny, location=location.absolute)plotshape((isSignalLabelEnabled and exitShort) ? zlsma : na, title='SHORT EXIT', style=shape.circle, color=rajah, size=size.tiny, location=location.absolute)barcolor(color=isTradeOpen == 'long' ? mediumAquamarine : isTradeOpen == 'short' ? carrotOrange : na)// -- Long Exits --if (exitLong and strategy.position_size > 0) strategy.close('long', comment='EXIT_LONG')// -- Short Exits --if (exitShort and strategy.position_size < 0) strategy.close('short', comment='EXIT_SHORT')// -- Long Entries --if (enterLong) strategy.entry('long', strategy.long, comment='ENTER_LONG')// -- Short Entries --if (enterShort) strategy.entry('short', strategy.short, comment='ENTER_SHORT')