Strategy · Pine Script v5 · On the chart

Sassiz Chandelier Exit

by sassiz-root

This Pine Script v5 strategy calculates ATR-based trailing stops for crypto trading on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code97
Settings15inputs
LicenceMIT
Last update3 years ago23 Feb 2023

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

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.

Details

Published by

sassiz-root on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
ATR Periodint22length
ATR Multiplierfloat3.0mult
Show Buy/Sell Labels ?booltrueshowLabels
Use Close Price for Extremums ?booltrueuseClose
Highlight State ?booltruehighlightState
sl Longfloat0.985slLong
tp longfloat1.03tpLong
sl shortfloat1.015slShort
tp shortfloat0.97tpShort
From Monthint4FromMonth
From Dayint25FromDay
From Yearint2022FromYear
Show all 15 settings
SettingTypeDefaultVariable
To Monthint5ToMonth
To Dayint5ToDay
To Yearint2022ToYear
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

330 stars

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

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger bands + Aroon [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

Nasdaq Prop Firm Strategy

by TradersPost
218 stars

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

Strategy v6 TrendSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Nasdaq Prop Firm Strategy

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.

Strategy v5 AI / machine learningTrend
Updated 1 year ago · None stated GitHub repository of Machine Learning: Perceptron-Based Strategy [5] (v.3)
106 stars

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

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]

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