PINE LIBRARY

ZigzagLite

Updated
Library "ZigzagLite"
Lighter version of the Zigzag Library. Without indicators and sub-component divisions

method getPrices(pivots)
  Gets the array of prices from array of Pivots
  Namespace types: Pivot[]
  Parameters:
    pivots (Pivot[]): array<Pivot> array of Pivot objects
  Returns: array<float> array of pivot prices

method getBars(pivots)
  Gets the array of bars from array of Pivots
  Namespace types: Pivot[]
  Parameters:
    pivots (Pivot[]): array<Pivot> array of Pivot objects
  Returns: array<int> array of pivot bar indices

method getPoints(pivots)
  Gets the array of chart.point from array of Pivots
  Namespace types: Pivot[]
  Parameters:
    pivots (Pivot[]): array<Pivot> array of Pivot objects
  Returns: array<chart.point> array of pivot points

method getPoints(this)
  Namespace types: Zigzag
  Parameters:
    this (Zigzag)

method calculate(this, ohlc, ltfHighTime, ltfLowTime)
  Calculate zigzag based on input values and indicator values
  Namespace types: Zigzag
  Parameters:
    this (Zigzag): Zigzag object
    ohlc (float[]): Array containing OHLC values. Can also have custom values for which zigzag to be calculated
    ltfHighTime (int): Used for multi timeframe zigzags when called within request.security. Default value is current timeframe open time.
    ltfLowTime (int): Used for multi timeframe zigzags when called within request.security. Default value is current timeframe open time.
  Returns: current Zigzag object

method calculate(this)
  Calculate zigzag based on properties embedded within Zigzag object
  Namespace types: Zigzag
  Parameters:
    this (Zigzag): Zigzag object
  Returns: current Zigzag object

method nextlevel(this)
  Namespace types: Zigzag
  Parameters:
    this (Zigzag)

method clear(this)
  Clears zigzag drawings array
  Namespace types: ZigzagDrawing[]
  Parameters:
    this (ZigzagDrawing[]): array<ZigzagDrawing>
  Returns: void

method clear(this)
  Clears zigzag drawings array
  Namespace types: ZigzagDrawingPL[]
  Parameters:
    this (ZigzagDrawingPL[]): array<ZigzagDrawingPL>
  Returns: void

method drawplain(this)
  draws fresh zigzag based on properties embedded in ZigzagDrawing object without trying to calculate
  Namespace types: ZigzagDrawing
  Parameters:
    this (ZigzagDrawing): ZigzagDrawing object
  Returns: ZigzagDrawing object

method drawplain(this)
  draws fresh zigzag based on properties embedded in ZigzagDrawingPL object without trying to calculate
  Namespace types: ZigzagDrawingPL
  Parameters:
    this (ZigzagDrawingPL): ZigzagDrawingPL object
  Returns: ZigzagDrawingPL object

method drawfresh(this, ohlc)
  draws fresh zigzag based on properties embedded in ZigzagDrawing object
  Namespace types: ZigzagDrawing
  Parameters:
    this (ZigzagDrawing): ZigzagDrawing object
    ohlc (float[]): values on which the zigzag needs to be calculated and drawn. If not set will use regular OHLC
  Returns: ZigzagDrawing object

method drawcontinuous(this, ohlc)
  draws zigzag based on the zigzagmatrix input
  Namespace types: ZigzagDrawing
  Parameters:
    this (ZigzagDrawing): ZigzagDrawing object
    ohlc (float[]): values on which the zigzag needs to be calculated and drawn. If not set will use regular OHLC
  Returns: [array<line> zigzaglines, array<label> zigzaglabels]

PivotCandle
  PivotCandle represents data of the candle which forms either pivot High or pivot low or both
  Fields:
    _high (series float): High price of candle forming the pivot
    _low (series float): Low price of candle forming the pivot
    length (series int): Pivot length
    pHighBar (series int): represents number of bar back the pivot High occurred.
    pLowBar (series int): represents number of bar back the pivot Low occurred.
    pHigh (series float): Pivot High Price
    pLow (series float): Pivot Low Price

Pivot
  Pivot refers to zigzag pivot. Each pivot can contain various data
  Fields:
    point (chart.point): pivot point coordinates
    dir (series int): direction of the pivot. Valid values are 1, -1, 2, -2
    level (series int): is used for multi level zigzags. For single level, it will always be 0
    ratio (series float): Price Ratio based on previous two pivots
    sizeRatio (series float)

ZigzagFlags
  Flags required for drawing zigzag. Only used internally in zigzag calculation. Should not set the values explicitly
  Fields:
    newPivot (series bool): true if the calculation resulted in new pivot
    doublePivot (series bool): true if the calculation resulted in two pivots on same bar
    updateLastPivot (series bool): true if new pivot calculated replaces the old one.

Zigzag
  Zigzag object which contains whole zigzag calculation parameters and pivots
  Fields:
    length (series int): Zigzag length. Default value is 5
    numberOfPivots (series int): max number of pivots to hold in the calculation. Default value is 20
    offset (series int): Bar offset to be considered for calculation of zigzag. Default is 0 - which means calculation is done based on the latest bar.
    level (series int): Zigzag calculation level - used in multi level recursive zigzags
    zigzagPivots (Pivot[]): array<Pivot> which holds the last n pivots calculated.
    flags (ZigzagFlags): ZigzagFlags object which is required for continuous drawing of zigzag lines.

ZigzagObject
  Zigzag Drawing Object
  Fields:
    zigzagLine (series line): Line joining two pivots
    zigzagLabel (series label): Label which can be used for drawing the values, ratios, directions etc.

ZigzagProperties
  Object which holds properties of zigzag drawing. To be used along with ZigzagDrawing
  Fields:
    lineColor (series color): Zigzag line color. Default is color.blue
    lineWidth (series int): Zigzag line width. Default is 1
    lineStyle (series string): Zigzag line style. Default is line.style_solid.
    showLabel (series bool): If set, the drawing will show labels on each pivot. Default is false
    textColor (series color): Text color of the labels. Only applicable if showLabel is set to true.
    maxObjects (series int): Max number of zigzag lines to display. Default is 300
    xloc (series string): Time/Bar reference to be used for zigzag drawing. Default is Time - xloc.bar_time.
    curved (series bool): Boolean field to print curved zigzag - used only with polyline implementation

ZigzagDrawing
  Object which holds complete zigzag drawing objects and properties.
  Fields:
    zigzag (Zigzag): Zigzag object which holds the calculations.
    properties (ZigzagProperties): ZigzagProperties object which is used for setting the display styles of zigzag
    drawings (ZigzagObject[]): array<ZigzagObject> which contains lines and labels of zigzag drawing.

ZigzagDrawingPL
  Object which holds complete zigzag drawing objects and properties - polyline version
  Fields:
    zigzag (Zigzag): Zigzag object which holds the calculations.
    properties (ZigzagProperties): ZigzagProperties object which is used for setting the display styles of zigzag
    zigzagLabels (label[])
    zigzagLine (series polyline): polyline object of zigzag lines
Release Notes
v2

Updated:
Pivot
  Pivot refers to zigzag pivot. Each pivot can contain various data
  Fields:
    point (chart.point): pivot point coordinates
    dir (series int): direction of the pivot. Valid values are 1, -1, 2, -2
    level (series int): is used for multi level zigzags. For single level, it will always be 0
    ratio (series float): Price Ratio based on previous two pivots
    sizeRatio (series float): ratio of current zigzag wave size in comparison to last zigzag wave in the same direction
    barRatio (series float): Bar Ratio based on previous two pivots
Release Notes
v3
arrayshewhomustnotbenamedtechindicatortrendoscopeZigzag

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.

Disclaimer