PINE LIBRARY

zigzagplus

ที่อัปเดต:
This is same as existing zigzag library with respect to functionality. But, there is a small update with respect to how arrays are used internally. This also leads to issues with backward compatibility. Hence I decided to make this as new library instead of updating the older one.

Below are the major changes:

  • Earlier version uses array.unshift for adding new elements and array.pop for removing old elements. But, since array.unshift is considerably slower than alternative method array.push. Hence, this library makes use of array.push method to achieve performance.
  • While array.push increases the performance significantly, there is also an issue with removing as we no longer will be able to remove the element using pop which is again faster than shift (which need to shit all the elements by index). Hence, have removed the logic of removing elements for zigzag pivots after certain limit. Will think further about it once I find better alternative of handling it.
  • These implementation change also mean that zigzag pivots received by calling method will be ordered in reverse direction. Latest pivots will be stored with higher array index whereas older pivots are stored with lower array index. This is also the reason why backward compatibility is not achievable with this code change.



Library "zigzagplus"
Library dedicated to zigzags and related indicators

zigzag(length, useAlternativeSource, source, oscillatorSource, directionBias) zigzag: Calculates zigzag pivots and generates an array
  Parameters:
    length: : Zigzag Length
    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, , source, linecolor, linewidth, linestyle, oscillatorSource, directionBias, showHighLow, showRatios, showDivergence) drawzigzag: Calculates and draws zigzag pivots
  Parameters:
    length: : Zigzag Length
    : 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
เอกสารเผยแพร่
Added numberOfPivots back and using remove to remove the older elements instead of shift as this is found to be yielding better performance over testing.
arraystechindicatorzigzaglibrary

ไลบรารีไพน์

ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์ซไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน

คำจำกัดสิทธิ์ความรับผิดชอบ