The rules at a glance
- Market: any major pair on the 4-hour chart; the example uses USDJPY
- Long line: the highest high of the last 22 candles minus 3 × ATR (22); it only moves up while the price stays above it
- Short line: the lowest low of the last 22 candles plus 3 × ATR (22); it only moves down while the price stays below it
- Entry: a close above the short line flips the direction to long: buy at that close if the price is above the 200 EMA (shorts: a close below the long line, under the 200 EMA)
- Stop and exit: the long line, updated on every candle: it starts as the stop loss and then trails behind the price
- Target: none: the trade runs until the trailing stop is hit
- Size: risk 0.5% to 1% of the account on the distance from the entry to the long line
What the ATR measures
The Average True Range (ATR) is the average size of a candle's full range, including any gap from the previous close. J. Welles Wilder introduced it in 1978. It says nothing about direction; it tells you how far the price usually moves in one candle. That makes it a natural ruler for stops: a stop three ATRs away is wide in a volatile market and tight in a quiet one, without you changing anything.
The chandelier exit
The chandelier exit was developed by Chuck LeBeau and made widely known through Alexander Elder's books. The long stop hangs from the highest high of the last 22 candles, like a chandelier from a ceiling, at three times the 22-period ATR below it. On a daily chart, 22 candles is about a month of trading. As the price makes new highs, the line rises with it. In the plain formula it can slip lower when the ATR widens or an old high drops out of the 22 candles; this script, like the popular TradingView versions, doesn't let it fall while the price stays above it.
The short version mirrors it: the lowest low of the last 22 candles plus 3 × ATR. When the price closes above the short line, the downtrend is over by this measure and the direction flips to long. That flip is the entry.
| ATR multiple | What changes |
|---|---|
| 2 × ATR | A tighter stop: gives back less of each move, but gets shaken out by normal pullbacks more often |
| 3 × ATR | The usual default, and this strategy's setting |
| 4 × ATR | A wider stop: survives deeper pullbacks, gives back more when the trend ends, and needs a smaller lot size |
The rules, step by step
1. Draw the two lines
Add the free script (or one of TradingView's community "Chandelier Exit" indicators; in the popular version by everget, untick "Use Close Price for Extremums" to match these rules) to a 4-hour chart, plus a 200 EMA. The script shows only the line that's active for the current direction.
2. Enter on the flip
When a candle closes above the short line, the direction flips to long. Buy at that close if the price is above the 200 EMA. For a short, the close must be below the long line with the price under the 200 EMA.
3. Let the long line be your stop
Your stop is the long line. Move it up to the new line after every candle, never down. The distance from the entry to the line at the start is your risk, and the lot size comes from it.
4. Exit when the stop is hit
There's no target. The trade closes when the price falls to the trailing stop. If that also flips the direction to short and the price is below the 200 EMA, the strategy can go short.
Worked example: USDJPY, 4-hour chart
Long stop (22-high − 3 ATR) Short line (22-low + 3 ATR)
After a pullback, USDJPY closes at 150.112, above the short line. The direction flips to long, and the price is above the 200 EMA, so it's a buy. The long line at that moment is 149.162, 95 pips below the entry; with an ATR of 36 pips, that's the 22-candle high minus three ATRs.
| USDJPY long | |
|---|---|
| Entry | 150.112 |
| Initial stop (the long line) | 149.162, 95 pips away |
| Pip value | ¥1,000 a lot, about $6.66 at 150.11 |
| Lot size at 1% of $10,000 | $100 ÷ (95 pips × $6.66) = 0.158, rounded down to 0.15 lots |
| Loss if the initial stop had been hit | about $95 |
| Exit (trailing stop hit) | 152.973, 48 candles later |
| Result | +286.1 pips, about 3.0R: ¥42,915, about $281 |
As USDJPY climbs, the long line climbs under it, and by the end it sits well above the entry: the trade can no longer lose. The price peaks at 154.046 and the stop is hit on the way down, 107 pips below the top. Giving back part of the move is the price of a trailing stop. On yen pairs one pip is 0.01 and is worth ¥1,000 on one lot, so the dollar value moves with USDJPY itself.
Chandelier exit or Supertrend?
Both are ATR trailing stops that flip direction, and on a chart they look alike. The Supertrend hangs its line from the middle of each candle (the average of the high and the low) plus or minus the ATR multiple; the chandelier exit hangs it from the highest high or lowest low of the look-back period. Because the highest high is never below a candle's midpoint, with the same ATR and multiple the chandelier line sits at least as close to the price as the Supertrend, and usually closer after a strong run. Neither is better in general; they're different rulers.
Risk management
- Size from the initial distance. Three ATRs on a 4-hour chart can be 80 to 150 pips on USDJPY, so the lot size is small.
- Move the stop every candle. If you trade it by hand, update the stop order after each candle closes. A trailing stop that isn't moved is just a fixed stop.
- Expect whipsaws in ranges. When the market goes sideways, the direction can flip back and forth for small losses. The 200 EMA filter cuts some of them.
- Gaps. Over a weekend, the price can open beyond the stop, and the loss can be bigger than planned.
Common mistakes
- Moving the stop down to "give the trade room". That turns a trailing stop back into hope.
- Using a tiny multiple on a fast market. A 1 × ATR trailing stop on USDJPY gets hit by ordinary noise.
- Taking every flip in a range. Flips come thick and fast when there's no trend.
- Forgetting the pip value on yen pairs. It's about $6 to $7 a pip on one lot at today's levels, not $10.
Backtest it yourself on TradingView
This page doesn't quote a win rate or a profit figure, and you should be wary of anyone who does without showing the test. Results change with the market, the dates, the data feed and the costs you put in. The honest way is to run the test yourself, and the free script below does the work in a couple of minutes.
- Open the chart. On TradingView, open USDJPY on the 4-hour chart.
- Add the script. Open the Pine Editor from the Pine icon in the panel on the right of the chart (older layouts have it as a tab under the chart), delete the code that's already there, paste this strategy's code and click "Add to chart".
- Put in your costs. Open the strategy's settings and go to Properties. Enter your broker's commission and a little slippage. A test without costs flatters every strategy, and short-term ones most of all.
- Read the Strategy Tester. The panel under the chart shows the net profit, the maximum drawdown, the profit factor, the number of trades and a list of every trade. Click a few trades and check on the chart that each one follows the rules. Trade sizes are shown in units rather than lots: 100,000 units is one lot of a forex pair, and 100 ounces is one lot of gold.
- Change one setting at a time. Compare the multiple (2, 3 and 4 × ATR), the look-back (14, 22 and 30 candles), the 200 EMA filter on and off, and the 4-hour chart against the daily. Then try the chandelier line as the exit for one of your own entries.
As a rough guide, don't trust a result with fewer than 100 trades, a profit factor under 1 once costs are in, or a drawdown you couldn't sit through with real money. Settings tuned to look good on one stretch of history often fail on the next, so check the same settings on dates you didn't tune them on, then demo trade the strategy for a few weeks. How much history you can test depends on your TradingView plan: the free plan loads 5,000 candles, which is a few months of 15-minute candles but years of daily ones.
The script sizes each trade from the stop loss and your risk percentage, starts with $10,000 and assumes 1:100 leverage (a 1% margin setting), so the tester doesn't flag margin calls on normal forex trade sizes. Change these under Properties to match your account. By default TradingView fills orders at the open of the candle after the signal, so the fill can differ a little from the signal candle's close.
Download the free Pine Script and PDF
The script is written in Pine Script version 6 for this guide and follows the rules above. It can't read the economic calendar, so skipping news days is up to you. It's free to use, change and share. The PDF is a one-page cheat sheet with the chandelier formula, the rules, a worked example and a checklist, to keep next to your chart.
Show the code (Pine Script v6, 61 lines)
//@version=6
// ATR Trailing Stop (Chandelier Exit) strategy by PipLedger (https://pipledgerfx.com/atr-trailing-stop-strategy)
// Trails a stop 3 x ATR below the highest high of the last 22 candles (above the lowest low for shorts). A close beyond the opposite line flips the direction; the strategy enters on flips in the direction of the 200 EMA and exits on the trailing stop.
// The line and direction logic follows the "Chandelier Exit" indicator by Alex Orekhov (everget) on TradingView, which is published under GPL-3.0,
// so this script is shared under GPL-3.0 too: free to use, change and share. For education and backtesting only; not financial advice.
strategy("PipLedger: ATR Trailing Stop (Chandelier)", shorttitle="Chandelier", overlay=true, initial_capital=10000, pyramiding=0, default_qty_type=strategy.fixed, default_qty_value=1, margin_long=1, margin_short=1, currency=currency.USD)
// ---------- Inputs
len = input.int(22, "Look-back and ATR length", minval=2)
mult = input.float(3.0, "ATR multiple", minval=0.5, step=0.25)
useTrend = input.bool(true, "Only go long above the 200 EMA and short below it")
riskPct = input.float(1.0, "Risk per trade (% of equity)", minval=0.1, maxval=5.0, step=0.1)
// ---------- Helpers
fx = strategy.convert_to_account(1.0) // one unit of the chart's quote currency in account currency (1 on USD-quoted charts)
calcQty(float entry, float stop) =>
float dist = math.abs(entry - stop)
dist > 0 and not na(fx) ? strategy.equity * riskPct / 100 / (dist * syminfo.pointvalue * fx) : 0.0
atr = ta.atr(len)
ema200 = ta.ema(close, 200)
// ---------- Chandelier lines: they only move in the trade's favour while the price holds above (below) them
float longStop = ta.highest(high, len) - mult * atr
float shortStop = ta.lowest(low, len) + mult * atr
float lsPrev = nz(longStop[1], longStop)
float ssPrev = nz(shortStop[1], shortStop)
longStop := close[1] > lsPrev ? math.max(longStop, lsPrev) : longStop
shortStop := close[1] < ssPrev ? math.min(shortStop, ssPrev) : shortStop
var int dir = 1
dir := close > ssPrev ? 1 : close < lsPrev ? -1 : dir
flipUp = dir == 1 and dir[1] == -1
flipDn = dir == -1 and dir[1] == 1
// ---------- Orders
flat = strategy.position_size == 0
longSig = flat and flipUp and (not useTrend or close > ema200)
shortSig = flat and flipDn and (not useTrend or close < ema200)
if longSig
float q = calcQty(close, longStop)
if q > 0 and close > longStop
strategy.entry("Long", strategy.long, qty=q)
if shortSig
float q = calcQty(close, shortStop)
if q > 0 and close < shortStop
strategy.entry("Short", strategy.short, qty=q)
// the trailing stop is re-sent on every candle at the latest line (entry fills at the next open, so the order is set now)
if strategy.position_size > 0 or longSig
strategy.exit("Long exit", "Long", stop=longStop)
if strategy.position_size < 0 or shortSig
strategy.exit("Short exit", "Short", stop=shortStop)
// ---------- Chart
plot(dir == 1 ? longStop : na, "Long trailing stop", color=color.new(color.teal, 0), linewidth=2, style=plot.style_linebr)
plot(dir == -1 ? shortStop : na, "Short trailing stop", color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr)
plot(useTrend ? ema200 : na, "200 EMA", color=color.new(color.gray, 0))
plotshape(longSig, "Long", shape.triangleup, location.belowbar, color.teal, size=size.small)
plotshape(shortSig, "Short", shape.triangledown, location.abovebar, color.red, size=size.small)Trading this from India
Residents can trade EURUSD, GBPUSD and USDJPY futures and options on NSE and BSE through a SEBI-registered broker. The contracts are quoted the same way as the spot pair, one lot is 1,000 units of the base currency, and they're cash-settled in rupees. They trade only from 9 a.m. to 7:30 p.m. IST, volumes are thin and not every broker offers them, so check the hours and the spread first. On the exchange contracts one USDJPY lot is $1,000, so a pip is worth ¥10 a lot. Trading forex or CFDs with offshore online platforms isn't allowed for residents under FEMA, even if the app is easy to download. Details are in is forex trading legal in India.
Related strategies: ADX trend following, 20 and 50 EMA pullback, EMA and RSI(2), RSI divergence, 9 and 21 EMA crossover, MACD and 200 EMA, RSI 60/40. All 34 strategies are compared on one page in forex trading strategies.