PINE LIBRARY
Atualizado zigzag

⬜ Zigzag at your fingertips.
Creating zigzag array is more simpler than ever. All you need to do is:
▶ Import library:
▶ And invoke zigzag to get all the details.
More examples in the code where you can get retracement ratios, zigzag direction, divergence etc.
Library "zigzag"
Library dedicated to zigzags and related indicators
zigzag(length, numberOfPivots, useAlternativeSource, source, oscillatorSource, directionBias) zigzag: Calculates zigzag pivots and generates an array
Parameters:
Returns:
drawzigzag(length, numberOfPivots, , source, linecolor, linewidth, linestyle, oscillatorSource, directionBias, showHighLow, showRatios, showDivergence) drawzigzag: Calculates and draws zigzag pivots
Parameters:
Returns:
Creating zigzag array is more simpler than ever. All you need to do is:
▶ Import library:
Pine Script®
import HeWhoMustNotBeNamed/<libraryname>/<version> as zgi
▶ And invoke zigzag to get all the details.
Pine Script®
zgi.drawzigzag(zigzagLength)
More examples in the code where you can get retracement ratios, zigzag direction, divergence etc.
Library "zigzag"
Library dedicated to zigzags and related indicators
zigzag(length, numberOfPivots, useAlternativeSource, source, oscillatorSource, directionBias) zigzag: Calculates zigzag pivots and generates an array
Parameters:
- length: : Zigzag Length
- numberOfPivots: : Max number of pivots to return in the array. Default is 20
- useAlternativeSource: : If set uses the source for genrating zigzag. Default is false
- source: : Alternative source used only if useAlternativeSource is set to true. Default is close
- oscillatorSource: : Oscillator source for calculating divergence
- directionBias: : Direction bias for calculating divergence
Returns:
- zigzagpivots : Array containing zigzag pivots
- zigzagpivotbars : Array containing zigzag pivot bars
- zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
- zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
- zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
- zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
- zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
- zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
- newPivot : Returns true if new pivot created
- doublePivot : Returns true if two new pivots are created on same bar (Happens in case of candles with long wicks and shorter zigzag lengths)
drawzigzag(length, numberOfPivots, , source, linecolor, linewidth, linestyle, oscillatorSource, directionBias, showHighLow, showRatios, showDivergence) drawzigzag: Calculates and draws zigzag pivots
Parameters:
- length: : Zigzag Length
- numberOfPivots: : Max number of pivots to return in the array. Default is 20
- : useAlternativeSource: If set uses the source for genrating zigzag. Default is false
- source: : Alternative source used only if useAlternativeSource is set to true. Default is close
- linecolor: : zigzag line color
- linewidth: : zigzag line width
- linestyle: : zigzag line style
- oscillatorSource: : Oscillator source for calculating divergence
- directionBias: : Direction bias for calculating divergence
- showHighLow: : show highlow label
- showRatios: : show retracement ratios
- showDivergence: : Show divergence on label (Only works if divergence data is available - that is if we pass valid oscillatorSource and directionBias input)
Returns:
- zigzagpivots : Array containing zigzag pivots
- zigzagpivotbars : Array containing zigzag pivot bars
- zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
- zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
- zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
- zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
- zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
- zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
- zigzaglines : Returns array of zigzag lines
- zigzaglabels : Returns array of zigzag labels
Notas de Lançamento
Fixed a minor zigzag drawing errorNotas de Lançamento
Performance Updates:- Using array.remove in place of array.shift
- Using array.insert in place of array.unshift
Notas de Lançamento
v4Added options to provide different oscillator sources for pivot high and pivot low for divergence calculation.
Notas de Lançamento
v5Created czigzag method which can take custom high/low sources for both candlesticks and oscillators. This can be useful if we need to create zigzag on different type of candle source such as Heikin Ashi Candles
Added:
czigzag(length, numberOfPivots, highSource, lowSource, oscillatorHighSource, oscillatorLowSource, directionBias) czigzag: Calculates zigzag pivots and generates an array based on custom high and low source
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
highSource: : High Source for prices to calculate zigzag.
lowSource: : Low source for prices to calculate zigzag.
oscillatorHighSource: : Oscillator high source for calculating divergence
oscillatorLowSource: : Oscillator high source for calculating divergence
directionBias: : Direction bias for calculating divergence
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
newPivot : Returns true if new pivot created
doublePivot : Returns true if two new pivots are created on same bar (Happens in case of candles with long wicks and shorter zigzag lengths)
Notas de Lançamento
v6Added:
drawczigzag(length, numberOfPivots, highSource, lowSource, oscillatorHighSource, oscillatorLowSource, directionBias, showHighLow, showRatios, showDivergence, linecolor, linewidth, linestyle) drawczigzag: Calculates and draws zigzag pivots and generates an array based on custom high and low source
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
highSource: : High Source for prices to calculate zigzag.
lowSource: : Low source for prices to calculate zigzag.
oscillatorHighSource: : Oscillator high source for calculating divergence
oscillatorLowSource: : Oscillator high source for calculating divergence
directionBias: : Direction bias for calculating divergence
showHighLow: : show highlow label
showRatios: : show retracement ratios
showDivergence: : Show divergence on label (Only works if divergence data is available - that is if we pass valid oscillatorSource and directionBias input)
linecolor: : zigzag line color
linewidth: : zigzag line width
linestyle: : zigzag line style
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
zigzaglines : Returns array of zigzag lines
zigzaglabels : Returns array of zigzag labels
Notas de Lançamento
v7Updated:
drawczigzag(length, numberOfPivots, highSource, lowSource, oscillatorHighSource, oscillatorLowSource, directionBias, showHighLow, showRatios, showDivergence, linecolor, linewidth, linestyle) drawczigzag: Calculates and draws zigzag pivots and generates an array based on custom high and low source
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
highSource: : High Source for prices to calculate zigzag.
lowSource: : Low source for prices to calculate zigzag.
oscillatorHighSource: : Oscillator high source for calculating divergence
oscillatorLowSource: : Oscillator high source for calculating divergence
directionBias: : Direction bias for calculating divergence
showHighLow: : show highlow label
showRatios: : show retracement ratios
showDivergence: : Show divergence on label (Only works if divergence data is available - that is if we pass valid oscillatorSource and directionBias input)
linecolor: : zigzag line color
linewidth: : zigzag line width
linestyle: : zigzag line style
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
zigzaglines : Returns array of zigzag lines
zigzaglabels : Returns array of zigzag labels
Notas de Lançamento
v8Correcting drawczigzag - label issue
Notas de Lançamento
v9Updated:
drawczigzag(length, numberOfPivots, highSource, lowSource, oscillatorHighSource, oscillatorLowSource, directionBias, showHighLow, showRatios, showDivergence, showDoubleDivergence, linecolor, linewidth, linestyle) drawczigzag: Calculates and draws zigzag pivots and generates an array based on custom high and low source
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
highSource: : High Source for prices to calculate zigzag.
lowSource: : Low source for prices to calculate zigzag.
oscillatorHighSource: : Oscillator high source for calculating divergence
oscillatorLowSource: : Oscillator high source for calculating divergence
directionBias: : Direction bias for calculating divergence
showHighLow: : show highlow label
showRatios: : show retracement ratios
showDivergence: : Show divergence on label (Only works if divergence data is available - that is if we pass valid oscillatorSource and directionBias input)
showDoubleDivergence: : Show double divergence label
linecolor: : zigzag line color
linewidth: : zigzag line width
linestyle: : zigzag line style
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
zigzagdoubledivergence : Array of double divergence sentiment at each pivot
zigzaglines : Returns array of zigzag lines
zigzaglabels : Returns array of zigzag labels
Notas de Lançamento
v10Notas de Lançamento
v11Updated:
zigzag(length, numberOfPivots, useAlternativeSource, source, oscillatorSource, directionBias, divergenceOption) zigzag: Calculates zigzag pivots and generates an array
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
useAlternativeSource: : If set uses the source for genrating zigzag. Default is false
source: : Alternative source used only if useAlternativeSource is set to true. Default is close
oscillatorSource: : Oscillator source for calculating divergence
directionBias: : Direction bias for calculating divergence
divergenceOption: : 1 - hidden/regular, 2 - regular, 3 - hidden
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
newPivot : Returns true if new pivot created
doublePivot : Returns true if two new pivots are created on same bar (Happens in case of candles with long wicks and shorter zigzag lengths)
czigzag(length, numberOfPivots, highSource, lowSource, oscillatorHighSource, oscillatorLowSource, directionBias, divergenceOption) czigzag: Calculates zigzag pivots and generates an array based on custom high and low source
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
highSource: : High Source for prices to calculate zigzag.
lowSource: : Low source for prices to calculate zigzag.
oscillatorHighSource: : Oscillator high source for calculating divergence
oscillatorLowSource: : Oscillator high source for calculating divergence
directionBias: : Direction bias for calculating divergence
divergenceOption: : 1 - hidden/regular, 2 - regular, 3 - hidden
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
zigzagdoubledivergence : Array of double divergence sentiment at each pivot
newPivot : Returns true if new pivot created
doublePivot : Returns true if two new pivots are created on same bar (Happens in case of candles with long wicks and shorter zigzag lengths)
Notas de Lançamento
v12Notas de Lançamento
v13Notas de Lançamento
v14Added:
drawczigzag2(length, numberOfPivots, highSource, lowSource, oscillatorHighSource, oscillatorLowSource, directionBias, showHighLow, showRatios, showDivergence, showDoubleDivergence, linecolor, linewidth, linestyle) drawczigzag2: Same as drawczigzag. But, returns newPivot and doublePivot bools as well.
Parameters:
length: : Zigzag Length
numberOfPivots: : Max number of pivots to return in the array. Default is 20
highSource: : High Source for prices to calculate zigzag.
lowSource: : Low source for prices to calculate zigzag.
oscillatorHighSource: : Oscillator high source for calculating divergence
oscillatorLowSource: : Oscillator high source for calculating divergence
directionBias: : Direction bias for calculating divergence
showHighLow: : show highlow label
showRatios: : show retracement ratios
showDivergence: : Show divergence on label (Only works if divergence data is available - that is if we pass valid oscillatorSource and directionBias input)
showDoubleDivergence: : Show double divergence label
linecolor: : zigzag line color
linewidth: : zigzag line width
linestyle: : zigzag line style
Returns: zigzagpivots : Array containing zigzag pivots
zigzagpivotbars : Array containing zigzag pivot bars
zigzagpivotdirs : Array containing zigzag pivot directions (Lower High : 1, Higher High : 2, Lower Low : -2 and Higher Low : -1)
zigzagpivotratios : Array containing zigzag retracement ratios for each pivot
zigzagoscillators : Array of oscillator values at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagoscillatordirs: Array of oscillator directions (HH, HL, LH, LL) at pivots. Will have valid values only if valid oscillatorSource is provided as per input.
zigzagtrendbias : Array of trend bias at pivots. Will have valid value only if directionBias series is sent in input parameters
zigzagdivergence : Array of divergence sentiment at each pivot. Will have valid values only if oscillatorSource and directionBias inputs are provided
zigzagdoubledivergence : Array of double divergence sentiment at each pivot
zigzaglines : Returns array of zigzag lines
zigzaglabels : Returns array of zigzag labels
Biblioteca do Pine
No verdadeiro espirito do TradingView, o autor desse código Pine o publicou como uma biblioteca de código aberto, para que outros programadores Pine da nossa comunidade possam reusa-los. Parabéns ao autor! Você pode usar essa biblioteca privadamente ou em outras publicações de código aberto, mas a reutilização desse código em publicações é regida pelas Regras da Casa.
Trial - trendoscope.io/trial
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.
Biblioteca do Pine
No verdadeiro espirito do TradingView, o autor desse código Pine o publicou como uma biblioteca de código aberto, para que outros programadores Pine da nossa comunidade possam reusa-los. Parabéns ao autor! Você pode usar essa biblioteca privadamente ou em outras publicações de código aberto, mas a reutilização desse código em publicações é regida pelas Regras da Casa.
Trial - trendoscope.io/trial
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.