1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
97 lines of Pine Script v5 from sassiz_chandelier_exit_strategy-v1.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.
sassiz_chandelier_exit_strategy-v1.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
strategy("sassiz chandelier Exit", overlay=true)
// Chandelier Exit script may be freely distributed under the terms of the GPL-3.0 license.
length = input.int(22,title="ATR Period", minval=1)
mult = input.float(3.0,title="ATR Multiplier",step=0.1, minval=0.0)
showLabels = input.bool(true,title="Show Buy/Sell Labels ?")
useClose = input.bool(true,title="Use Close Price for Extremums ?")
highlightState = input.bool(true,title="Highlight State ?")
atr = mult * ta.atr(length)
longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
var color longColor = color.new(color.green,80)
var color shortColor = color.new(color.red,80)
longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
buySignal = dir == 1 and dir[1] == -1
//plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
//plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
sellSignal = dir == -1 and dir[1] == 1
//plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
//plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)
longFillColor = highlightState ? (dir == 1 ? longColor : na) : na
shortFillColor = highlightState ? (dir == -1 ? shortColor : na) : na
fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)
changeCond = dir != dir[1]
// alertcondition(changeCond, title="Alert: CE Direction Change", message="Chandelier Exit has changed direction!")
// alertcondition(buySignal, title="Alert: CE Buy", message="Chandelier Exit Buy!")
// alertcondition(sellSignal, title="Alert: CE Sell", message="Chandelier Exit Sell!")
//add by sassiz
slLong = input.float(0.985,title="sl Long",step=0.01)
tpLong = input.float(1.03,title="tp long",step=0.01)
slShort = input.float(1.015,title="sl short",step=0.01)
tpShort = input.float(0.97,title="tp short",step=0.01)
// plotshape(PK_X_PD_Long,title="Signal Long",style=shape.triangleup,color=color.green,location=location.bottom,size=size.small)
// plotshape(PK_X_PD_Short,title="Signal Short",style=shape.triangledown,color=color.red,location=location.top,size=size.small)
FromMonth = input.int(defval = 4, title = "From Month", minval = 1, maxval = 12)
FromDay = input.int(defval = 25, title = "From Day", minval = 1, maxval = 31)
FromYear = input.int(defval = 2022, title = "From Year", minval = 2010)
ToMonth = input.int(defval = 5, title = "To Month", minval = 1, maxval = 12)
ToDay = input.int(defval = 5, title = "To Day", minval = 1, maxval = 31)
ToYear = input.int(defval = 2022, title = "To Year", minval = 999)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() => time >= start and time <= finish ? true : false
bgcolor(color=window()?color.new(color.blue,95):na)
if(window())
//strategy long
strategy.entry('buy',strategy.long,when=buySignal)// and strategy.position_size == 0)
strategy.exit('buy',limit = strategy.position_avg_price * tpLong,stop=strategy.position_avg_price * tpLong)//,trail_price=longStopPrev)
//strategy.exit('buy',limit = strategy.position_avg_price * tpLong,stop=longStop>strategy.position_avg_price * slLong?(longStop-(longStop*0.2/100)):strategy.position_avg_price * slLong)
//strategy short
strategy.entry('short',strategy.short,when=sellSignal)// and strategy.position_size == 0)
strategy.exit('short',limit = strategy.position_avg_price * tpShort,stop=strategy.position_avg_price * slShort)
//strategy.exit('short',limit = strategy.position_avg_price * tpShort,stop=shortStop<strategy.position_avg_price * slShort?shortStop:strategy.position_avg_price * slShort)
//alertcondition(PK_X_PD_Short or PK_X_PD_Long, "SStochEma Signal Alert", "Go Trade with SStochEma Signal")
//setup trade takeprofit and stoploss
inTrade = strategy.position_size //if <0 trade position is short and if >0 trade postion is long and if = 0 no postion
//for sell and buy
entery = plot(inTrade<0 ? strategy.position_avg_price :strategy.position_avg_price,color=color.purple,style=plot.style_circles,title="enteryShort",trackprice=true)
profit = plot(inTrade<0 ? strategy.position_avg_price * tpShort:strategy.position_avg_price * tpLong,color=color.green,style=plot.style_circles,title="profitShort",trackprice=true)
stop = plot(inTrade<0 ? strategy.position_avg_price * slShort:strategy.position_avg_price * slLong,color=color.orange,style=plot.style_circles,title="stopShort",trackprice=true)
fill(entery,profit,color= color.new(color.green,65))
fill(entery,stop,color= color.new(color.red,65))
Overview
Sassiz Chandelier Exit defines a long stop as the highest close minus ATR times multiplier and a short stop as the lowest close plus ATR times multiplier. The script dynamically updates these stops when price crosses previous levels and tracks trend direction changes. It plots the long and short stops, fills the area between the mid-price and stops according to current direction, and generates buy/sell signals on direction switches. Main settings control ATR period, multiplier, label visibility, close usage for extrema, state highlighting, and custom SL/TP multipliers. All elements draw directly on the price chart.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
ATR Period
int
22
length
ATR Multiplier
float
3.0
mult
Show Buy/Sell Labels ?
bool
true
showLabels
Use Close Price for Extremums ?
bool
true
useClose
Highlight State ?
bool
true
highlightState
sl Long
float
0.985
slLong
tp long
float
1.03
tpLong
sl short
float
1.015
slShort
tp short
float
0.97
tpShort
From Month
int
4
FromMonth
From Day
int
25
FromDay
From Year
int
2022
FromYear
Show all 15 settings
Setting
Type
Default
Variable
To Month
int
5
ToMonth
To Day
int
5
ToDay
To Year
int
2022
ToYear
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.
This strategy calculates Bollinger Bands and Aroon oscillator values to identify mean-reversion opportunities. It enters a long position using full equity when the closing price crosses below the lower Bollinger Band while Aroon Up remains above a user-specifi
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
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
This strategy uses multiple VWAP anchors and a custom Lull indicator to generate buy and sell signals on the Nasdaq price chart. It plots the VWAP trend line and three VWAP anchors with customizable colors and mitigation methods. The Lull indicator produces si
This strategy implements a single-layer perceptron machine learning model built from scratch to generate trading signals directly on the price chart. It calculates predictions based on sample size, threshold settings, and optional volatility or volume filters.
This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st