PINE LIBRARY
Обновлено

ZigZagCore

1 135
ZigZagCore

ZigZagCore is a generic ZigZag engine that works with any user-defined threshold (ATR-based, volatility-based, fixed ticks, etc.).

API
Pine Script®


zz_update(state, thr)
  Parameters:
    state (ZzState)
    thr (float)

ZzState
  Fields:
    dir (series int)
    highSinceLow (series float)
    lowSinceHigh (series float)
    lastHighLevel (series float)
    lastLowLevel (series float)
    lastHighIndex (series int)
    lastLowIndex (series int)
    highSinceLowIndex (series int)
    lowSinceHighIndex (series int)
    isNewHigh (series bool)
    isNewLow (series bool)

Directional State
dir = 1 → market is in an upswing
dir = -1 → market is in a downswing
dir = na → initial undecided state

Live Swing Tracking (Unconfirmed Leg)
Continuously updated swing extremes:
highSinceLow — highest price since the last confirmed low
lowSinceHigh — lowest price since the last confirmed high
Their corresponding bar indices

These fields describe the current active swing leg, which updates every bar until a pivot is confirmed.

Pivot Detection
A pivot confirms only when price moves beyond the prior swing extreme by more than threshold. When this occurs, the library sets:
isNewHigh = true (on the detection bar only) and updates lastHighLevel, lastHighIndex
isNewLow = true and updates lastLowLevel, lastLowIndex
Информация о релизе
v2
Added highBroken and lowBroken fields in ZzState

Updated:
ZzState
  Fields:
    dir (series int)
    highSinceLow (series float)
    lowSinceHigh (series float)
    lastHighLevel (series float)
    lastLowLevel (series float)
    lastHighIndex (series int)
    lastLowIndex (series int)
    highSinceLowIndex (series int)
    lowSinceHighIndex (series int)
    isNewHigh (series bool)
    isNewLow (series bool)
    highBroken (series bool)
    lowBroken (series bool)
Информация о релизе
v3 added 2 new features:
-Stale bars: a direction switch will happen if a high/low has been standing and stale for N bars
-High/low break: a direction switch will be forced if a high/low is broken, despite the volatility threshold not being met

Both these changes are designed to improve stability in the face of rising and falling volatility measurements, while maintaining the direction switching rule (high must follow low, must follow high, etc.)

Updated:
zz_update(state, thr, staleBars)
  Parameters:
    state (ZzState)
    thr (float)
    staleBars (int)
Информация о релизе
v4

Bugfix for stale bars logic to ensure correct pivot bar detection.
Информация о релизе
v5 Bugfix for live leg.
Информация о релизе
v6
Refactor for handling stale bars and break logic together.

Updated:
zz_update(state, thr, staleBars, switchOnPriorLevelBreak)
  Parameters:
    state (ZzState)
    thr (float)
    staleBars (int)
    switchOnPriorLevelBreak (bool)

ZzState
  Fields:
    dir (series int)
    lastHighLevel (series float)
    lastLowLevel (series float)
    lastHighIndex (series int)
    lastLowIndex (series int)
    candidateHigh (series float)
    candidateLow (series float)
    candidateHighIndex (series int)
    candidateLowIndex (series int)
    pullbackLow (series float)
    reboundHigh (series float)
    pullbackLowIndex (series int)
    reboundHighIndex (series int)
    highSinceLow (series float)
    lowSinceHigh (series float)
    highSinceLowIndex (series int)
    lowSinceHighIndex (series int)
    isNewHigh (series bool)
    isNewLow (series bool)
    highBroken (series bool)
    lowBroken (series bool)

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.