TradingView indicator calculations

Chandelier Exit: calculate the level before choosing an exit rule

Chandelier Exit places a long exit reference below a rolling high and a short exit reference above a rolling low, offset by a multiple of Average True Range (ATR). The raw formulas can move in either direction. A stop that only tightens, a change of trend state, and an executed exit each require additional rules. Check which version a TradingView script implements before comparing its signals.

See the decision guide

The rolling-extreme formula

For bar t, let HH(N) be the highest high and LL(N) the lowest low across the latest N bars, including t. With ATR length A and positive multiplier k, rawLong = HH(N) - k × ATR(A), and rawShort = LL(N) + k × ATR(A). TradingView exposes separate extreme and ATR lengths. StockCharts documents 22 bars and 3 ATR as its default convention; those values are a starting specification, not an optimum.

  • True range = max(high - low, abs(high - previous close), abs(low - previous close)). The previous close captures gaps that a high-low range misses.
  • The Pine example uses ta.atr(A), the RMA of true range. After its initial average, the Wilder update is ATR[t] = ((A - 1) × ATR[t-1] + TR[t]) / A. An SMA or EMA choice changes the result.
  • With previous close 100, high 108, and low 105, true range is max(3, 8, 5) = 8. If A = 4 and previous ATR = 2, the updated ATR is (3 × 2 + 8) / 4 = 3.5.
InputMeaningComparison trap
Extreme length NRolling window in chart bars22 hourly bars are not 22 trading days.
ATR length ASmoothing window for true rangeMatching N does not establish matching A or smoothing.
Multiplier kDistance in ATR units from the extreme3 ATR below the high is not 3 ATR below entry.
Extreme sourceHigh and low in this exampleHighest close and lowest close define a different variant.

Why a raw Chandelier line can loosen

The exact long-level change is ΔrawLong = ΔHH - k × ΔATR. A new high therefore raises the line only if its increase exceeds the multiplied ATR increase. An old high leaving the window can also lower it. For the short line, ΔrawShort = ΔLL + k × ΔATR. These are consequences of the formulas, not separate market signals.

  • For one uninterrupted long position, a chosen ratchet is longStop[t] = max(longStop[t-1], rawLong[t]). For a short position, shortStop[t] = min(shortStop[t-1], rawShort[t]). Initialize at entry and clear the state at exit.
  • A ratchet has memory beyond the rolling window. The same current high, low, and ATR can give different active stops after different entry histories.
  • Some scripts reset a ratchet on a trend-state change instead of a real trade. Read that reset condition; the indicator state need not equal your account position.

Follow five calculated levels through a volatility increase

These hypothetical checkpoints supply rolling extremes and ATR directly to isolate the stop arithmetic; they are not consecutive OHLC bars or an ATR reconstruction. Use k = 3. Initialize a long ratchet at A and assume the same long position remains open through E. Each ratchet update is intended for the next decision interval.

  • At B, the high rises by 2 but the ATR buffer grows by 1.5. The raw long level rises only 0.5.
  • At C, the unchanged high and larger buffer lower rawLong to 103. The ratchet retains 104.5.
  • At D, the rolling high falls by 1 while the buffer shrinks by 1.5. The raw line rises by 0.5 despite the lower high, but remains below the ratchet.
CheckpointHH / LLATRRaw longRaw shortLong ratchet
A110 / 1002.0104.0106.0104.0
B112 / 1012.5104.5108.5104.5
C112 / 1023.0103.0111.0104.5
D111 / 1022.5103.5109.5104.5
E113 / 1042.0107.0110.0107.0

Specify direction changes without inventing a buy signal

Two exit levels alone do not define a single trend direction. An explicit demonstration policy could start neutral, switch to long after a confirmed close above the previous short level, switch to short after a confirmed close below the previous long level, and otherwise retain the prior state. Equality leaves the state unchanged. If both tests are true, retain the prior state and flag the overlap for review. That policy is a design choice, not a universal Chandelier definition.

  • The bands can overlap: rawLong - rawShort = HH - LL - 2 × k × ATR. When that difference is positive, a close between them can satisfy both directional tests. A script must state its conflict rule.
  • A close below a long reference can be an exit condition for an existing long. It does not establish the entry, size, or justification for opening a short.
  • Using the current level lets the current bar change both the threshold and the price being tested. Using the previous completed level fixes the threshold for that bar; neither policy is interchangeable with the other.

Separate a touch, a confirmed breach, and a fill

Assume a long reference of 104.5 was known before the bar began. The following cases compare decisions against that fixed level. They do not use the newly calculated closing level retrospectively as an order that existed throughout the bar.

  • TradingView documents that its broker emulator fills a price-based order crossed in an interbar gap at the next open. In the gap example, the modeled price is 101 before additional execution assumptions, not 104.5.
  • A live stop-market order can fill worse than its trigger; a stop-limit order can remain unfilled. Order type, available liquidity, slippage, and broker handling remain separate from the indicator.
  • A line computed at the close cannot prove that its final value was available at the earlier low. Historical OHLC also does not reveal every intrabar event. Test order creation time and fill assumptions separately.
Price pathClose-confirmed ruleResting stop-order implication
Open 106, low 104, close 105No close below 104.5A pre-existing sell stop may trigger on the dip.
Open 106, low 103, close 104Breach known at the closeA resting stop and a later close decision have different timing.
Previous close 106; next open 101Waiting for the close delays the decisionThe gap passes 104.5; that price is not guaranteed.

Pine Script v6: inspect raw levels and confirmed breaches

This indicator plots the raw rolling formulas and marks every confirmed close below the previous long reference or above the previous short reference. It deliberately has no position state, ratchet, entry, or order placement. The markers are repeated conditions, not first-cross signals, and both can appear when the references overlap. Use standard price bars and the chart timeframe.

  • Wait for both a complete extreme window and an available ATR. Compare the Data Window values on completed bars before interpreting markers.
  • Match symbol, feed, session, chart type, timeframe, lengths, and loaded history when checking another implementation. This example does not request a higher timeframe.
  • Syntax validation checks whether the source is accepted; it does not verify profitability, broker fills, or agreement with a third-party script.
Raw plots can move while the live bar is open. Only breach conditions wait for confirmation. This is an indicator, not a backtest or an execution system.pine
//@version=6
indicator("Chandelier raw levels: inspection", overlay = true)
int extremeLength = input.int(22, "Extreme length", minval = 1)
int atrLength = input.int(22, "ATR length", minval = 1)
float multiplier = input.float(3.0, "ATR multiplier", minval = 0.1, step = 0.1)
float highestPrice = ta.highest(high, extremeLength)
float lowestPrice = ta.lowest(low, extremeLength)
float atr = ta.atr(atrLength)
bool ready = bar_index >= extremeLength - 1 and not na(atr)
float rawLong = ready ? highestPrice - multiplier * atr : na
float rawShort = ready ? lowestPrice + multiplier * atr : na
bool longBreach = barstate.isconfirmed and not na(rawLong[1]) and close < rawLong[1]
bool shortBreach = barstate.isconfirmed and not na(rawShort[1]) and close > rawShort[1]
plot(rawLong, "Raw long reference", color = color.blue, linewidth = 2)
plot(rawShort, "Raw short reference", color = color.orange, linewidth = 2)
plotshape(longBreach, "Close below prior long", shape.triangledown, location.abovebar, color.red, size = size.tiny)
plotshape(shortBreach, "Close above prior short", shape.triangleup, location.belowbar, color.green, size = size.tiny)
alertcondition(longBreach, "Long reference breached", "Confirmed close below previous Chandelier long level")
alertcondition(shortBreach, "Short reference breached", "Confirmed close above previous Chandelier short level")

Turn the calculation into a testable strategy specification

Give the Pine Script AI Coding Agent the raw formula, entry rule, ratchet lifecycle, equality rule, and confirmation policy. Request intermediate plots and a separate syntax check. For a long position, verify that the initialized stop is below the intended entry and reject an invalid placement rather than silently changing the formula.

  • Check volatility expansion, a high aging out of the window, an intrabar recovery, a gap, and an exit followed by re-entry. Re-entry must not inherit the previous trade's ratchet.
  • If comparing parameters with Strategy Optimizer, keep entry rules and execution assumptions fixed. Define training and later test windows yourself, freeze the selected settings, and inspect the later sample without retuning.
  • A larger multiplier increases the distance from the extreme for fixed inputs. Whether it improves results depends on the strategy and sample. Compare costs, drawdown, and nearby parameter values rather than choosing only the highest historical return.
Where Pineify fits

Pine Script AI Coding Agent

Draft a strategy from your Chandelier formula and explicit state rules, then request syntax checking and compare its plotted values with your acceptance cases.

Also useful: Strategy Optimizer. Compare configurable strategy inputs after defining the test period, costs, and execution rules. Reserve a separate period to check the selected parameters.

Build a Chandelier rule set

Frequently asked questions

Educational indicator and hypothetical calculation examples, not investment advice. Chandelier levels cannot prevent losses or guarantee execution prices. Syntax acceptance and historical testing do not establish future performance.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.