Strategy · Pine Script v5 · On the chart

Chandelier Exit - Eterna

by EternaHybridExchange

This strategy calculates volatility-based Chandelier Exit bands using the Average True Range and high/low extremes, paired with an optional exponential moving average trend filter.

View on GitHub

GitHub stars9on the repository
Pine versionv5runs as is
Lines of code91
Settings7inputs
LicenceMIT
Last update7 months ago12 Mar 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

91 lines of Pine Script v5 from strategies/trend-following/chandelier-exit/strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

strategy.pine
//@version=5
strategy("Chandelier Exit - Eterna", 
         overlay=true, 
         initial_capital=10000,
         default_qty_type=strategy.percent_of_equity, 
         default_qty_value=10,
         commission_type=strategy.commission.percent,
         commission_value=0.075)

// ==================== Parameters ====================
atrLength = input.int(22, "ATR Length", minval=1)
atrMultiplier = input.float(3.0, "ATR Multiplier", minval=0.5, step=0.1)
trendEMA = input.int(50, "Trend Filter EMA", minval=1)
useTrendFilter = input.bool(true, "Use EMA Trend Filter")
leverage = input.int(5, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, step=0.001)

webhookMessage = input.string('{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}", "size":' + str.tostring(positionSize) + ', "leverage":' + str.tostring(leverage) + '}', 
                               "Webhook JSON", group="Webhook")

// ==================== Chandelier Calculation ====================
atrValue = ta.atr(atrLength)

// Chandelier Exit Long: Highest high - (ATR × Multiplier)
highestHigh = ta.highest(high, atrLength)
chandelierLong = highestHigh - (atrValue * atrMultiplier)

// Chandelier Exit Short: Lowest low + (ATR × Multiplier)
lowestLow = ta.lowest(low, atrLength)
chandelierShort = lowestLow + (atrValue * atrMultiplier)

// Trend filter
emaFilter = ta.ema(close, trendEMA)
uptrend = close > emaFilter
downtrend = close < emaFilter

// ==================== Entry Conditions ====================
// Long entry: Price crosses above Chandelier Long line
longBreakout = ta.crossover(close, chandelierLong)
longCondition = useTrendFilter ? (longBreakout and uptrend) : longBreakout

// Short entry: Price crosses below Chandelier Short line
shortBreakdown = ta.crossunder(close, chandelierShort)
shortCondition = useTrendFilter ? (shortBreakdown and downtrend) : shortBreakdown

// Exit: Price crosses back through respective Chandelier line
exitLong = ta.crossunder(close, chandelierLong)
exitShort = ta.crossover(close, chandelierShort)

// ==================== Strategy Execution ====================
if longCondition
    strategy.entry("Long", strategy.long, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "buy"))

if shortCondition
    strategy.entry("Short", strategy.short, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "sell"))

if exitLong
    strategy.close("Long", alert_message='{"action":"close", "symbol":"{{ticker}}"}')

if exitShort
    strategy.close("Short", alert_message='{"action":"close", "symbol":"{{ticker}}"}')

// ==================== Plotting ====================
// Plot Chandelier lines
longStopPlot = plot(chandelierLong, "Chandelier Long Stop", color=color.green, linewidth=2, style=plot.style_stepline)
shortStopPlot = plot(chandelierShort, "Chandelier Short Stop", color=color.red, linewidth=2, style=plot.style_stepline)

// Plot trend filter
plot(useTrendFilter ? emaFilter : na, "Trend EMA", color=color.orange, linewidth=1)

// Entry signals
plotshape(longCondition, "Long Entry", shape.triangleup, location.belowbar, color.green, size=size.normal)
plotshape(shortCondition, "Short Entry", shape.triangledown, location.abovebar, color.red, size=size.normal)

// Exit signals
plotshape(exitLong and strategy.position_size > 0, "Long Exit", shape.xcross, location.abovebar, color.red, size=size.small)
plotshape(exitShort and strategy.position_size < 0, "Short Exit", shape.xcross, location.belowbar, color.green, size=size.small)

// Fill between chandelier lines
fill(longStopPlot, shortStopPlot, color=color.new(color.gray, 90))

// Background color based on position
positionBg = strategy.position_size > 0 ? color.new(color.green, 95) : strategy.position_size < 0 ? color.new(color.red, 95) : color.new(color.gray, 98)
bgcolor(positionBg)

// Show ATR value
var label atrLabel = na
if bar_index % 30 == 0
    label.delete(atrLabel)
    atrLabel := label.new(bar_index, low, "ATR: " + str.tostring(atrValue, "#.##"), 
                          color=color.blue, textcolor=color.white, size=size.small, style=label.style_label_up)

Overview

Chandelier Exit - Eterna enters long when the close crosses above the long Chandelier line while above the EMA, and enters short on a breakdown below the short line while below the EMA. Positions close when the price crosses back across the respective Chandelier level. It plots both bands, the EMA filter, and execution shapes on the main chart.

Details

Published by

EternaHybridExchange on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages

Markets

Crypto

Timeframes

H4 and above, M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingautomated-tradingbacktestingbybitcrypto-tradingeternamcppine-scripttrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
ATR Lengthint22atrLength
ATR Multiplierfloat3.0atrMultiplier
Trend Filter EMAint50trendEMA
Use EMA Trend FilterbooltrueuseTrendFilter
Leverageint5leverage
Position Sizefloat0.01positionSize
Webhook JSONstring'{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}webhookMessage
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
104 stars

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of Chandelier Exit & ZLSMA Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers