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 indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
72 lines of Pine Script v5 from ZigZag - ishod/Zigzag Lines - 7.pine.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.
Zigzag Lines - 7.pine.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @mebiele
// Thanks to @mmoiwgg, this is just a simplified and less fancy presentattion of your work
//@version=5
indicator('Zigzag Lines', overlay=true, max_lines_count=500)
//Inputs
zigperiod = input(defval=5, title='ZigZag Period', group='Zigzag')
zigsrc = input.string("close", title='Zig Zag Source',options=["close", "high/low"], group='Zigzag')
upcolor = input(defval=color.green, title='Zig Zag Up Color', group='Display')
downcolor = input(defval=color.red, title='Zig Zag Down Color', group='Display')
zigstyle = input.string(defval='Solid', title='Zig Zag Line Style', options=['Solid', 'Dotted'], group='Display')
zigwidth = input(defval=3, title='Zig zag Line Width', group='Display')
//Float
float highs = na
float lows = na
if zigsrc == "close"
highs := ta.highestbars(close, zigperiod) == 0 ? close : na
lows := ta.lowestbars(close, zigperiod) == 0 ? close : na
else
highs := ta.highestbars(high, zigperiod) == 0 ? high : na
lows := ta.lowestbars(low, zigperiod) == 0 ? low : na
//Variables
var dir1 = 0
iff_1 = lows and na(highs) ? -1 : dir1
dir1 := highs and na(lows) ? 1 : iff_1
var max_array_size = 100
var zigzagPivots = array.new_float(max_array_size)
var zigzagPivotBars = array.new_int(max_array_size)
add_to_arrays(pointer1, value, pointer2, bindex) =>
array.unshift(pointer2, bindex)
array.unshift(pointer1, value)
if array.size(pointer1) > max_array_size
array.pop(pointer1)
array.pop(pointer2)
update_arrays(pointer1, value, pointer2, bindex, dir) =>
if array.size(pointer1) == 0
add_to_arrays(pointer1, value, pointer2, bindex)
else
if dir == 1 and value > array.get(pointer1, 0) or dir == -1 and value < array.get(pointer1, 0)
array.set(pointer1, 0, value)
array.set(pointer2, 0, bindex)
0.
dir1changed = ta.change(dir1)
if highs or lows
if dir1changed
add_to_arrays(zigzagPivots, dir1 == 1 ? highs : lows, zigzagPivotBars, bar_index)
else
update_arrays(zigzagPivots, dir1 == 1 ? highs : lows, zigzagPivotBars, bar_index, dir1)
if array.size(zigzagPivots) >= 2
var line zzline1 = na
var label zzlabel1 = na
float val = array.get(zigzagPivots, 0)
int point = array.get(zigzagPivotBars, 0)
if ta.change(val) or ta.change(point)
float val1 = array.get(zigzagPivots, 1)
int point1 = array.get(zigzagPivotBars, 1)
if ta.change(val1) == 0 and ta.change(point1) == 0
line.delete(zzline1)
label.delete(zzlabel1)
// showline
zzline1 := line.new(x1=point, x2=point1, y1=val, y2=val1, color=dir1 == 1 ? upcolor : downcolor, width=zigwidth, style=zigstyle == 'Solid' ? line.style_solid : line.style_dotted)
zzline1
Overview
Users can select between bar closing prices or high/low extremes as the calculation source and adjust the detection period. Settings also allow full customization of line color, width, and style. Because the indicator evaluates extreme values over rolling bars and updates array elements as new highs or lows form, historical pivot connections repaint until subsequent bars consolidate.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
ZigZag Period
int
5
zigperiod
Zig Zag Source
string
close
zigsrc
Zig Zag Up Color
color
color.green
upcolor
Zig Zag Down Color
color
color.red
downcolor
Zig Zag Line Style
string
Solid
zigstyle
Zig zag Line Width
int
3
zigwidth
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.
Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us
This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and
This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale
This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur
The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on
This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up