Indicator · Pine Script v5 · On the chart

SuperChandelierIndicator

by darkshloser· code credited to Author: dkovache

Draws three ATR-based SuperTrend lines on the price chart, each with its own ATR period, multiplier, source and a wicks-or-close option.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code382
Settings19inputs
LicenceApache-2.0
Last update2 years ago15 Jul 2024

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

382 lines of Pine Script v5 from SuperChandelierIndicator.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

SuperChandelierIndicator.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Author: dkovache

//@version=5
indicator("SuperChandelierIndicator", overlay=true)

//============================================================================================================
// Constants
//============================================================================================================
var longColor = color.green
var shortColor = color.red

//============================================================================================================
// Variables to be set by GUI
//============================================================================================================
st1_length = input.int(defval=12, title="ST1 ATR Period", minval=1)
st1_mult = input.float(defval=3.0, title="ST1 ATR Multiplier", step=0.1, minval=0.1)
st1_wicks = input(defval=true, title="Take supertrend1 wicks into account ?")

st2_length = input.int(defval=10, title="ST2 ATR Period", minval=1)
st2_mult = input.float(defval=1, title="ST2 ATR Multiplier", step=0.1, minval=0.1)
st2_wicks = input(defval=true, title="Take supertrend2 wicks into account ?")

st3_length = input.int(defval=11, title="ST3 ATR Period", minval=1)
st3_mult = input.float(defval=2.0, title="ST3 ATR Multiplier", step=0.1, minval=0.1)
st3_wicks = input(defval=true, title="Take supertrend3 wicks into account ?")

src = input.source(defval=hl2, title="St1")
src2 = input.source(defval=hl2, title="St2")
src3 = input.source(defval=hl2, title="St3")

// Second timezone
second_timeframe = input.int(defval=60, title="Second timeframe for analyze", step=10, minval=10)


//============================================================================================================
// Calculations for the first Supertrend indicator on main timeframe
//============================================================================================================
atr = st1_mult * ta.atr(st1_length)
highPrice = st1_wicks ? high : close
lowPrice = st1_wicks ? low : close
dojiCandle = open == close and open == low and open == high

longStop = src - atr
longStopPrev = nz(longStop[1], longStop)

if longStop > 0
    if dojiCandle
        longStop := longStopPrev
    else
        longStop := (lowPrice[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop)
else
    longStop := longStopPrev


shortStop = src + atr
shortStopPrev = nz(shortStop[1], shortStop)

if shortStop > 0
    if dojiCandle
        shortStop := shortStopPrev
    else
        shortStop := (highPrice[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop)
else
    shortStop := shortStopPrev

var int dir = 1
dir :=
         dir == -1 and highPrice > shortStopPrev ? 1 :
         dir == 1 and lowPrice < longStopPrev ? -1 :
         dir

plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)


//============================================================================================================
// Calculations for the second Supertrend indicator on main timeframe
//============================================================================================================
atr2 = st2_mult * ta.atr(st2_length)
highPrice2 = st2_wicks ? high : close
lowPrice2 = st2_wicks ? low : close
dojiCandle := open == close and open == low and open == high

longStop2 = src2 - atr2
longStopPrev2 = nz(longStop2[1], longStop2)

if longStop2 > 0
    if dojiCandle
        longStop2 := longStopPrev2
    else
        longStop2 := (lowPrice2[1] > longStopPrev2 ? math.max(longStop2, longStopPrev2) : longStop2)
else
    longStop2 := longStopPrev2


shortStop2 = src2 + atr2 
shortStopPrev2 = nz(shortStop2[1], shortStop2)

if shortStop2 > 0
    if dojiCandle 
        shortStop2 := shortStopPrev2
    else
        shortStop2 := (highPrice2[1] < shortStopPrev2 ? math.min(shortStop2, shortStopPrev2) : shortStop2)
else
    shortStop2 := shortStopPrev2

var int dir2 = 1
dir2 :=
         dir2 == -1 and highPrice2 > shortStopPrev2 ? 1 :
         dir2 == 1 and lowPrice2 < longStopPrev2 ? -1 :
         dir2

plot(dir2 == 1 ? longStop2 : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
plot(dir2 == 1 ? na : shortStop2, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)


//============================================================================================================
// Calculations for the third Supertrend indicator on main timeframe
//============================================================================================================
atr3 = st3_mult * ta.atr(st3_length)
highPrice3 = st3_wicks ? high : close
lowPrice3 = st3_wicks ? low : close
dojiCandle := open == close and open == low and open == high


longStop3 = src3 - atr3
longStopPrev3 = nz(longStop3[1], longStop3)

if longStop3 > 0
    if dojiCandle
        longStop3 := longStopPrev3
    else
        longStop3 := (lowPrice3[1] > longStopPrev3 ? math.max(longStop3, longStopPrev3) : longStop3)
else
    longStop3 := longStopPrev3


shortStop3 = src3 + atr3 
shortStopPrev3 = nz(shortStop3[1], shortStop3)

if shortStop3 > 0
    if dojiCandle 
        shortStop3 := shortStopPrev3
    else
        shortStop3 := (highPrice3[1] < shortStopPrev3 ? math.min(shortStop3, shortStopPrev3) : shortStop3)
else
    shortStop3 := shortStopPrev3

var int dir3 = 1
dir3 :=
         dir3 == -1 and highPrice3 > shortStopPrev3 ? 1 :
         dir3 == 1 and lowPrice3 < longStopPrev3 ? -1 :
         dir3


plot(dir3 == 1 ? longStop3 : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
plot(dir3 == 1 ? na : shortStop3, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)


//============================================================================================================
// Calculations for the Supertrends in second timeframe
//============================================================================================================
calcSupertrend(_length, _mult, _wicks, _src) =>
    _atr = _mult * ta.atr(_length)
    _highPrice = _wicks ? request.security(syminfo.tickerid, str.tostring(second_timeframe), high) : request.security(syminfo.tickerid, str.tostring(second_timeframe), close)
    _lowPrice = _wicks ? request.security(syminfo.tickerid, str.tostring(second_timeframe), low) : request.security(syminfo.tickerid, str.tostring(second_timeframe), close)
    _dojiCandle = request.security(syminfo.tickerid, str.tostring(second_timeframe), open == close and open == low and open == high)

    _longStop = _src - _atr
    _longStopPrev = nz(_longStop[1], _longStop)

    if _longStop > 0
        if _dojiCandle
            _longStop := _longStopPrev
        else
            _longStop := (_lowPrice[1] > _longStopPrev ? math.max(_longStop, _longStopPrev) : _longStop)
    else
        _longStop := _longStopPrev

    _shortStop = _src + _atr
    _shortStopPrev = nz(_shortStop[1], _shortStop)

    if _shortStop > 0
        if _dojiCandle
            _shortStop := _shortStopPrev
        else
            _shortStop := (_highPrice[1] < _shortStopPrev ? math.min(_shortStop, _shortStopPrev) : _shortStop)
    else
        _shortStop := _shortStopPrev

    _dir = 1
    _dir :=
             _dir == -1 and _highPrice > _shortStopPrev ? 1 :
             _dir == 1 and _lowPrice < _longStopPrev ? -1 :
             _dir

    [_longStop, _shortStop, _dir]



[longStop1_sec_timeframe, shortStop1_sec_timeframe, dir1_sec_timeframe] = calcSupertrend(st1_length, st1_mult, st1_wicks, src)
[longStop2_sec_timeframe, shortStop2_sec_timeframe, dir2_sec_timeframe] = calcSupertrend(st2_length, st2_mult, st2_wicks, src2)
[longStop3_sec_timeframe, shortStop3_sec_timeframe, dir3_sec_timeframe] = calcSupertrend(st3_length, st3_mult, st3_wicks, src3)


//============================================================================================================
// Calculate Chandelier Exit 
//============================================================================================================

var string calcGroup = 'Calculation Chandelier Exit'
length_chandelier = input.int(title='ATR Period', defval=1, group=calcGroup)
mult_chandelier = input.float(title='ATR Multiplier', step=0.1, defval=2.0, group=calcGroup)
useClose_chandelier = input.bool(title='Use Close Price for Extremums', defval=true, group=calcGroup)

showLabels_chandelier = input.bool(title='Show Buy/Sell Labels', defval=true, group=calcGroup)
highlightState_chandelier = input.bool(title='Highlight State', defval=true, group=calcGroup)

awaitBarConfirmation_chandelier = input.bool(title="Await Bar Confirmation", defval=true, group=calcGroup)

atr_chandelier = mult_chandelier * ta.atr(length_chandelier)

longStop_chandelier = (useClose_chandelier ? ta.highest(close, length_chandelier) : ta.highest(length_chandelier)) - atr_chandelier
longStopPrev_chandelier = nz(longStop_chandelier[1], longStop_chandelier)
longStop_chandelier := close[1] > longStopPrev_chandelier ? math.max(longStop_chandelier, longStopPrev_chandelier) : longStop_chandelier

shortStop_chandelier = (useClose_chandelier ? ta.lowest(close, length_chandelier) : ta.lowest(length_chandelier)) + atr_chandelier
shortStopPrev_chandelier = nz(shortStop_chandelier[1], shortStop_chandelier)
shortStop_chandelier := close[1] < shortStopPrev_chandelier ? math.min(shortStop_chandelier, shortStopPrev_chandelier) : shortStop_chandelier



var int dir_chandelier = 1
dir_chandelier := close > shortStopPrev_chandelier ? 1 : close < longStopPrev_chandelier ? -1 : dir_chandelier

var color textColor = color.new(color.white, 0)

longStopPlot_chandelier = plot(dir_chandelier == 1 ? longStop_chandelier : na, title='Long Stop', style=plot.style_linebr, linewidth=2, color=color.new(longColor, 0))
buySignal_chandelier = dir_chandelier == 1 and dir_chandelier[1] == -1
plotshape(buySignal_chandelier ? longStop_chandelier : na, title='Long Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(longColor, 0))
plotshape(buySignal_chandelier and showLabels_chandelier ? longStop_chandelier : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(longColor, 0), textcolor=textColor)

shortStopPlot_chandelier = plot(dir_chandelier == 1 ? na : shortStop_chandelier, title='Short Stop', style=plot.style_linebr, linewidth=2, color=color.new(shortColor, 0))
sellSignal_chandelier = dir_chandelier == -1 and dir_chandelier[1] == 1
plotshape(sellSignal_chandelier ? shortStop_chandelier : na, title='Short Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(shortColor, 0))
plotshape(sellSignal_chandelier and showLabels_chandelier ? shortStop_chandelier : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(shortColor, 0), textcolor=textColor)



//============================================================================================================
//============================================================================================================
//
//                                                ANALYZES
//
//============================================================================================================
//============================================================================================================

condition_to_buy = dir == 1 and dir2 == 1 and dir3 == 1 and dir_chandelier == 1
condition_to_sell = dir == -1 and dir2 == -1 and dir3 == -1 and dir_chandelier == -1
condition_to_close = not condition_to_buy and not condition_to_sell

plot(condition_to_buy ? longStop_chandelier : na , style=plot.style_linebr, linewidth=4, color=color.new(color.blue, 0),  title="Buy")
plot(condition_to_sell ? shortStop_chandelier : na , style=plot.style_linebr, linewidth=4, color=color.new(color.purple, 0), title="Sell")


//============================================================================================================
// Alerts
//============================================================================================================
alertcondition(condition_to_buy and not condition_to_buy[1], title="Alert: Buy", message="Symbol: {{exchange}}:{{ticker}}")
alertcondition(condition_to_sell and not condition_to_sell[1], title="Alert: Sell", message="Symbol: {{exchange}}:{{ticker}}")
alertcondition(condition_to_close and not condition_to_close[1], title="Alert: Close position", message="Symbol: {{exchange}}:{{ticker}}")






// Plot new line in yellow when condition is met
// plot(dir_chandelier == 1 ? na : shortStop_chandelier, title='Short Stop', style=plot.style_linebr, linewidth=2, color=color.new(shortColor, 0))
// test = plot(condition_to_sell ? na : shortStop_chandelier, style=plot.style_linebr, linewidth=4, color=color.new(color.yellow, 0), title="New Line")

// plot(condition_to_buy ? shortStop_chandelier : na , style=plot.style_linebr, linewidth=4, color=color.new(color.yellow, 0), title="New Line")



// label.new(x=bar_index, y=high + 9, text=str.tostring(dir_chandelier), style=label.style_label_down, color=color.red, textcolor=color.black, size=size.small)
// label.new(x=bar_index, y=high + 12, text=str.tostring(dir3), style=label.style_label_down, color=color.red, textcolor=color.black, size=size.small)
// ======================= Analyzes ==============================
// // Analize main timeframe 
// var activePosition = false
// var activeColor = color.white
// var activeColorPrevState = color.white
// var isOpenPosition = false
// var isPositionLong = false

// activeColorPrevState := activeColor
// if direction1 > 0 and direction2 > 0 and direction3 > 0
//     activeColor := color.red
//     activePosition := true
// else if direction1 < 0 and direction2 < 0 and direction3 < 0
//     activeColor := color.green
//     activePosition := true
// else
//     activeColor := color.white
//     activePosition := false


// // Analyze second timeframe 
// // second_timeframe
// [trend1_second_timeframe, dir1_second_timeframe] = request.security(syminfo.tickerid, str.tostring(second_timeframe), ta.supertrend(st1_mult, st1_length))
// [trend2_second_timeframe, dir2_second_timeframe] = request.security(syminfo.tickerid, str.tostring(second_timeframe), ta.supertrend(st2_mult, st2_length))
// [trend3_second_timeframe, dir3_second_timeframe] = request.security(syminfo.tickerid, str.tostring(second_timeframe), ta.supertrend(st3_mult, st3_length))

// var underlyingLong = false
// var activePositionSecond = false


// if dir1_second_timeframe > 0 and dir2_second_timeframe > 0 and dir3_second_timeframe > 0
//     underlyingLong := false
//     activePositionSecond := true
// else if dir1_second_timeframe < 0 and dir2_second_timeframe < 0 and dir3_second_timeframe < 0
//     underlyingLong := true
//     activePositionSecond := true
// else
//     activePositionSecond := false
//     underlyingLong := false




// ===========================================  MAIN timeframe analyze =======================
// var activePosition = false
// var activeColor = color.blue
// var activeColorPrevState = color.blue

// var isOpenPosition = false
// var isPositionLong = false

// bool conditionEntered = false

// // Update the status of the previouse bar
// activeColorPrevState := activeColor


// if dir > 0 and dir2 > 0 and dir3 > 0
//     if not isOpenPosition
//         activeColor := color.green
//         activePosition := true
//         isOpenPosition := true
//         conditionEntered := true
//     else
//         conditionEntered := false
// else if dir < 0 and dir2 < 0 and dir3 < 0
//     if not isOpenPosition
//         activeColor := color.red
//         activePosition := true
//         isOpenPosition := true
//         conditionEntered := true
//     else
//         conditionEntered := false
// else
//     activeColor := color.blue
//     activePosition := false
//     isOpenPosition := false
//     conditionEntered := false

// plotshape(series=conditionEntered and activeColor == color.green, title="Signal", location=location.belowbar, color=longColor, style=shape.triangleup, size=size.small)
// plotshape(series=conditionEntered and activeColor == color.red, title="Signal", location=location.abovebar, color=shortColor, style=shape.triangledown, size=size.small)







// conditionLong = dir > 0 and dir2 > 0 and dir3 > 0
// // Plot a shape on the chart based on the condition
// plotshape(series=conditionLong, title="Up Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)

// conditionShort = dir < 0 and dir2 < 0 and dir3 < 0
// // Plot a shape on the chart based on the condition
// plotshape(series=conditionShort, title="Down Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

Overview

A second timeframe input supports a higher timeframe view, and a Chandelier-style exit layer with ATR length, multiplier, close-price extremes and an optional wait for bar confirmation can show buy and sell labels and state highlighting. Trailing lines flip colour between green and red when direction changes.

Details

Published by

darkshloser on GitHub

Code credit

Author: dkovache, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands

Markets

Any symbol

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
ST1 ATR Periodint12st1_length
ST1 ATR Multiplierfloat3.0st1_mult
Take supertrend1 wicks into account ?booltruest1_wicks
ST2 ATR Periodint10st2_length
ST2 ATR Multiplierfloat1st2_mult
Take supertrend2 wicks into account ?booltruest2_wicks
ST3 ATR Periodint11st3_length
ST3 ATR Multiplierfloat2.0st3_mult
Take supertrend3 wicks into account ?booltruest3_wicks
St1sourcehl2src
St2sourcehl2src2
St3sourcehl2src3
Show all 19 settings
SettingTypeDefaultVariable
Second timeframe for analyzeint60second_timeframe
ATR Periodint1length_chandelier
ATR Multiplierfloat2.0mult_chandelier
Use Close Price for ExtremumsbooltrueuseClose_chandelier
Show Buy/Sell LabelsbooltrueshowLabels_chandelier
Highlight StatebooltruehighlightState_chandelier
Await Bar ConfirmationbooltrueawaitBarConfirmation_chandelier
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

Chandelier Exit

by everget
948 stars

This indicator plots an ATR-based Chandelier Exit trailing stop on the price chart. It tracks a long stop under recent highs and a short stop above recent lows, then switches direction when price crosses the opposite stop. Buy and sell labels mark those flips.

Indicator v6 Volatility & bandsTrend Repaints
Updated 11 days ago · GPL-3.0 GitHub repository of Chandelier Exit

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
330 stars

Range Filter [Alorse] is a technical indicator overlay for TradingView designed to filter market volatility and identify price trends. It calculates a smoothed range based on historical volatility using a configurable sampling period and multiplier applied to

Indicator v5 TrendVolatility & bands
Updated 2 months ago · None stated GitHub repository of Range Filter [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 2 days ago · MIT GitHub repository of NVDA Trend Ribbon

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers