What it measures
The Chandelier Exit is a trailing stop that hangs from the highest point of the trend, like a chandelier from a ceiling. For a long position the stop sits a multiple of the ATR below the highest high of the last 22 bars; for a short, a multiple of the ATR above the lowest low. As the trend makes new extremes the stop follows, and when volatility rises the stop gives more room.
Chuck LeBeau developed it, and Alexander Elder's books helped make it a standard. It's an exit tool first, though many traders also use its flips as entries in the new direction.
The formula in words
- Compute the ATR over 22 bars (about one month of daily bars) and multiply it by 3.
- Long stop = highest high of the last 22 bars − 3 × ATR.
- Short stop = lowest low of the last 22 bars + 3 × ATR.
- While price stays above the long stop, the stop never moves down: each bar takes the higher of the new value and the previous stop. The short stop never moves up, by the same logic.
- The direction turns short when the close falls below the long stop, and long when the close rises above the short stop.
Steps 4 and 5 come from the popular TradingView implementation; LeBeau's original describes the stop level itself. Some versions measure from the highest close instead of the highest high, which the script offers as an option.
How traders read it
- Trailing a position. In a long trade, the stop sits at the long Chandelier line and the trade ends when price closes below it. Because the stop hangs from the high, a pullback has to exceed three ATRs from the peak to end the trade.
- Direction. Only one line is drawn at a time: below price while the direction is long, above it while short. It works like a Supertrend with the reference point at the extreme instead of the bar's midpoint.
- Stop distance for sizing. The distance from entry to the line is the risk per unit; size the position from it with the position size calculator.
- Volatility changes. After a spike in ATR, the raw stop can drop even while the high is unchanged. The ratchet in step 4 prevents that while the trade is on.
Common settings
| Setting | Typical value | Notes |
|---|---|---|
| Lookback | 22 | One month of daily bars. |
| ATR length | 22 | Usually the same as the lookback. |
| Multiplier | 3 | 2.5 for tighter exits, 3.5 to 4 for long-term trends. |
| Reference | Highest high and lowest low | The highest and lowest close give slightly tighter stops. |
Pine Script v6 code
The complete, self-contained script is below. Copy it into a new indicator in TradingView's Pine Editor, or download the .pine file.
//@version=6
indicator("Chandelier Exit", shorttitle = "Chandelier", overlay = true)
lookback = input.int(22, "Lookback (bars)", minval = 1, group = "Calculation")
atrLen = input.int(22, "ATR length", minval = 1, group = "Calculation")
mult = input.float(3.0, "ATR multiplier", minval = 0.1, step = 0.1, group = "Calculation")
useClose = input.bool(false, "Measure from the highest/lowest close instead of high/low", group = "Calculation")
upCol = input.color(color.teal, "Long stop", group = "Display")
dnCol = input.color(color.red, "Short stop", group = "Display")
dist = mult * ta.atr(atrLen)
highestHi = ta.highest(high, lookback)
highestCl = ta.highest(close, lookback)
lowestLo = ta.lowest(low, lookback)
lowestCl = ta.lowest(close, lookback)
rawLong = (useClose ? highestCl : highestHi) - dist
rawShort = (useClose ? lowestCl : lowestLo) + dist
var float longStop = na
var float shortStop = na
prevLong = longStop
prevShort = shortStop
// Each stop only moves in the trade's favour while price stays on its side, then restarts from the raw level.
longStop := not na(prevLong) and close[1] > prevLong ? math.max(rawLong, prevLong) : rawLong
shortStop := not na(prevShort) and close[1] < prevShort ? math.min(rawShort, prevShort) : rawShort
// Direction flips when the close crosses the opposite stop.
var int dir = 1
dir := not na(prevShort) and close > prevShort ? 1 : not na(prevLong) and close < prevLong ? -1 : dir
flipUp = dir == 1 and dir[1] == -1
flipDown = dir == -1 and dir[1] == 1
plot(dir == 1 ? longStop : na, "Long stop", color = upCol, linewidth = 2, style = plot.style_linebr)
plot(dir == -1 ? shortStop : na, "Short stop", color = dnCol, linewidth = 2, style = plot.style_linebr)
plotshape(flipUp, "Turns long", shape.labelup, location.belowbar, upCol, text = "Long", textcolor = color.white, size = size.tiny)
plotshape(flipDown, "Turns short", shape.labeldown, location.abovebar, dnCol, text = "Short", textcolor = color.white, size = size.tiny)
alertcondition(flipUp, "Chandelier turns long", "Close crossed above the Chandelier short stop on {{ticker}} ({{interval}}) at {{close}}")
alertcondition(flipDown, "Chandelier turns short", "Close crossed below the Chandelier long stop on {{ticker}} ({{interval}}) at {{close}}")The script draws only the active stop: the long stop in green while the direction is long, the short stop in red while it's short, with a label on each flip. Each stop ratchets in the trade's favour until price closes through it, the same logic as the ATR stop lines script.
Two alert conditions fire on flips. Flips use the close, so they're provisional until the bar closes; set alerts to Once per bar close.
Add it to your chart
- Open any chart on TradingView and open the Pine Editor.
- Create a new indicator, delete the template code and paste the script.
- Click Save, then Add to chart. Change lengths and levels from the indicator's settings.
Stuck on an error? See how to add a Pine Script indicator to TradingView.
Pitfalls
- Gaps. A stop is a level, not a guaranteed fill. Price can open well beyond it.
- Ranges. In sideways markets the direction flips back and forth. Taking every flip as an entry produces a series of small losses.
- Too tight a multiplier. A multiplier under 2 on daily bars often exits on normal pullbacks.
- Mixing versions. High-based and close-based versions give different levels and flips. Compare like with like.
Related reading
- Pine Script strategy.exit(): stop loss and take profit that behave as you expect
- MQL5 trailing stop: points, ATR and break-even code for MT5 Expert Advisors
- Position sizing and the 1% rule: how much to risk per trade
- ATR Stop-Loss Calculator (free tool)
- Position Size Calculator (free tool)
The script is an educational example: test it on your own markets before relying on it. Indicators describe the past; they don't predict the future. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.