Indicator · Pine Script v5 · On the chart

[JL] Supertrend Zone Pivot Point with Zigzag Fib

by WISEPLAT· code credited to Jesse.Lau

This indicator overlays a Supertrend calculation with filled trend zones and ATR-based premium or discount offset lines directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code190
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago20 Jun 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 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

190 lines of Pine Script v5 from ZigZag - ishod/[JL] Supertrend Zone Pivot Point with zigzag fib - 10.pine.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

[JL] Supertrend Zone Pivot Point with zigzag fib - 10.pine.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Jesse.Lau




//@version=5
indicator(title="[JL] Supertrend Zone Pivot Point with zigzag fib", overlay=true,max_labels_count=500,max_bars_back = 4900)
show_zigzag = input(true, "Show zigzag", group="Show")
show_fib = input(true, "Show fibonacci", group="Show")
show_supertrend = input(true, "Show supertrend", group="Show")
show_premiumdiscount = input(true, "Show premium/discount line", group="Show")

// Getting inputs
atrPeriod = input(10, "ATR Length")
factor = input.float(3, "Factor", step = 0.1)
atrline = input.float(1.5, "Premium/Discount", step = 0.1)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 and show_supertrend ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(direction > 0 and show_supertrend ? supertrend :na, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle, upTrend, show_supertrend ? color.new(color.green, 90):na, fillgaps=false)
fill(bodyMiddle, downTrend,show_supertrend ?  color.new(color.red, 90):na, fillgaps=false)

ATR = ta.atr(atrPeriod)
upatrline =  supertrend + atrline*ATR 
dnatrline = supertrend - atrline*ATR 

plot(direction < 0 and show_premiumdiscount ? upatrline : na, "Up ATR", color = color.white, style=plot.style_linebr)
plot(direction > 0 and show_premiumdiscount ? dnatrline : na, "Dn ATR", color = color.white, style=plot.style_linebr)




colorGroupTitle = "Text Color / Label Color"

textColorH = input(title="Pivot High", defval=color.white, inline="Pivot High", group=colorGroupTitle)
labelColorH = input(title="", defval=color.red, inline="Pivot High", group=colorGroupTitle)

textColorL = input(title="Pivot Low", defval=color.white, inline="Pivot Low", group=colorGroupTitle)
labelColorL = input(title="", defval=color.green, inline="Pivot Low", group=colorGroupTitle)

turnGreen = ta.change(direction) < 0
turnRed   = ta.change(direction) > 0


barsturngreen = bar_index - ta.valuewhen(turnGreen, bar_index, 0)
barsturnred = bar_index - ta.valuewhen(turnRed, bar_index, 0)
barsg = barsturngreen>0 ? barsturngreen : 1

h1 = ta.highest(high,barsg)
//plot(h1)
barsr = barsturnred>0 ? barsturnred : 1


l2 = ta.lowest(low,barsr) 
//plot(l2)
barsh = bar_index - ta.valuewhen(ta.change(h1),bar_index,0)
barsl = bar_index - ta.valuewhen(ta.change(l2),bar_index,0)
barsh2 = bar_index - ta.valuewhen(ta.change(h1),bar_index,1)
barsl2 = bar_index - ta.valuewhen(ta.change(l2),bar_index,1)
h1Index = 0
l2Index = 0
var label h1label = na
var label l2label = na
drawLabel(_offset, _pivot, _style, _color, _textColor) =>
    if not na(_pivot)
        label.new(bar_index-_offset, _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)
if turnRed
    
    
    h1label:=drawLabel(barsh, h1, label.style_label_down, labelColorH, textColorH)
    if show_zigzag
        line.new(bar_index - barsh, h1, bar_index-barsl2, l2[1], width = 3, color=color.lime)

if turnGreen
    
    
    l2label:=drawLabel(barsl, l2, label.style_label_up, labelColorL, textColorL)
    if show_zigzag
        line.new(bar_index - barsh2, h1[1], bar_index-barsl, l2, width = 3,color = color.fuchsia)

hh = ta.valuewhen(turnRed, h1, 0)
ll = ta.valuewhen(turnGreen, l2, 0)




mid_val = (hh + ll) / 2

// Plot lines for highest high and lowest low
var line hhLine = na
var line llLine = na
var line midline = na
var label fibLabelh = na
var label fibLabell = na
var label fibLabelm = na
var label fibLabel1 = na
var label fibLabel2 = na
var label fibLabel3 = na
var label fibLabel4 = na
var label fibLabel5 = na
var label fibLabel6 = na
var line fibLine1 = na
var line fibLine2 = na
var line fibLine3 = na
var line fibLine4 = na
var line fibLine5 = na
var line fibLine6 = na
if barstate.islast and show_fib
    while high[h1Index] != h1[1]
        h1Index := h1Index + 1

    while low[l2Index] != l2[1] 
        l2Index := l2Index + 1

    n = math.max(h1Index,l2Index)
    if not na(hhLine)
        line.delete(hhLine)
    if not na(llLine)
        line.delete(llLine)
    if not na(midline)
        line.delete(midline)
    if not na(fibLabelh)
        label.delete(fibLabelh)
    if not na(fibLabell)
        label.delete(fibLabell)
    
    if not na(fibLabelm)
        label.delete(fibLabelm)
    if not na(fibLabel1)
        label.delete(fibLabel1) 
    if not na(fibLabel2)
        label.delete(fibLabel2)
    if not na(fibLabel3)
        label.delete(fibLabel3)

    if not na(fibLabel4)
        label.delete(fibLabel4)
    if not na(fibLabel5)
        label.delete(fibLabel5)

    if not na(fibLabel6)
        label.delete(fibLabel6)
    if not na(fibLine1)
        line.delete(fibLine1)
    if not na(fibLine2)
        line.delete(fibLine2)
    if not na(fibLine3)
        line.delete(fibLine3)
    if not na(fibLine4)
        line.delete(fibLine4)
    if not na(fibLine5)
        line.delete(fibLine5)
    if not na(fibLine6)
        line.delete(fibLine6)
    hhLine := line.new(x1=bar_index-n+1, y1=hh, x2=bar_index, y2=hh, color=color.purple, width=1)
    fibLabelh := label.new(x=bar_index + 10, y=hh , text="1("+str.tostring(hh )+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)

    llLine := line.new(x1=bar_index-n+1, y1=ll, x2=bar_index, y2=ll, color=color.purple, width=1)
    fibLabell := label.new(x=bar_index + 10, y=ll , text="0("+str.tostring(ll )+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)

    midline := line.new(bar_index-n+1, mid_val, bar_index, mid_val, color=color.purple, width=1)
    fibLabelm := label.new(x=bar_index + 10, y=mid_val , text="0.5("+str.tostring(mid_val )+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)

    fibLabel1 := label.new(x=bar_index + 10, y=ll + 0.236*(hh-ll), text="0.236("+str.tostring(ll + 0.236*(hh-ll),"#.####")+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)
    
    fibLine1 := line.new(x1 = bar_index-n+1,y1 = ll + 0.236*(hh-ll),x2 = bar_index,y2 = ll + 0.236*(hh-ll),color = color.purple,width = 1)

    fibLabel2 := label.new(x=bar_index + 10, y=ll + 0.382*(hh-ll), text="0.382("+str.tostring(ll + 0.382*(hh-ll),"#.####")+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)
    
    fibLine2 := line.new(x1 = bar_index-n+1,y1 = ll + 0.382*(hh-ll),x2 = bar_index,y2 = ll + 0.382*(hh-ll),color = color.purple,width = 1)

    fibLabel3 := label.new(x=bar_index + 10, y=ll + 0.618*(hh-ll), text="0.618("+str.tostring(ll + 0.618*(hh-ll),"#.####")+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)
    
    fibLine3 := line.new(x1 = bar_index-n+1,y1 = ll + 0.618*(hh-ll),x2 = bar_index,y2 = ll + 0.618*(hh-ll),color = color.purple,width = 1)

    fibLabel4 := label.new(x=bar_index + 10, y=ll + 0.786*(hh-ll), text="0.786("+str.tostring(ll + 0.786*(hh-ll),"#.####")+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)
    
    fibLine4 := line.new(x1 = bar_index-n+1,y1 = ll + 0.786*(hh-ll),x2 = bar_index,y2 = ll + 0.786*(hh-ll),color = color.purple,width = 1)

    if close>supertrend
        fibLabel5 := label.new(x=bar_index + 10, y=ll + 1.618*(hh-ll), text="1.618("+str.tostring(ll + 1.618*(hh-ll),"#.####")+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)
        
        fibLine5 := line.new(x1 = bar_index-n+1,y1 = ll + 1.618*(hh-ll),x2 = bar_index,y2 = ll + 1.618*(hh-ll),color = color.purple,width = 1)
    if close<supertrend
        fibLabel6 := label.new(x=bar_index + 10, y=ll - 0.618*(hh-ll), text="-1.618("+str.tostring(ll - 0.618*(hh-ll),"#.####")+")", style = label.style_none,xloc=xloc.bar_index, yloc=yloc.price, color=color.white, textcolor=color.gray)
        
        fibLine6 := line.new(x1 = bar_index-n+1,y1 = ll - 0.618*(hh-ll),x2 = bar_index,y2 = ll - 0.618*(hh-ll),color = color.purple,width = 1)

Overview

Upon direction changes in the Supertrend, it identifies highest highs and lowest lows during the preceding trend to place pivot price labels and render custom ZigZag trendlines connecting high and low pivots. Users can independently toggle the visibility of the Supertrend plot, premium/discount offset lines, ZigZag connections, and Fibonacci levels.

Details

Published by

WISEPLAT on GitHub

Code credit

Jesse.Lau, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Support & resistance, 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
Show zigzagbooltrueshow_zigzag
Show fibonaccibooltrueshow_fib
Show supertrendbooltrueshow_supertrend
Show premium/discount linebooltrueshow_premiumdiscount
ATR Lengthint10atrPeriod
Factorfloat3factor
Premium/Discountfloat1.5atrline
Pivot Highcolorcolor.whitetextColorH
labelColorHcolorcolor.redlabelColorH
Pivot Lowcolorcolor.whitetextColorL
labelColorLcolorcolor.greenlabelColorL
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

[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

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

ATR Trailing Stop

by mihakralj
99 stars

Calculates an ATR-based trailing stop overlaid on the price chart to assist with trend identification and stop placement. Using a specified ATR period and multiplier, it projects upper and lower bounds around the closing price. The stop line ratchets up during

Indicator v5 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of ATR Trailing Stop

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 6 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots

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