PINE LIBRARY
Cập nhật ZoneKit

Library "ZoneKit"
Generic 3-candle price-gap zone detection and drawing utilities.
Detects a gap between two candle extremes separated by one middle
candle, with an optional stricter mode requiring displacement on
both sides of the gap. Builds a box (and optional midline) to
represent the zone once detected.
scanZone(mode, h0, h2, l0, l2, c0, c1, c2, o0, o1, o2, minGap)
Scans three consecutive candles for a price-gap zone in either
direction.
Parameters:
mode (string): "Standard" for a plain 3-candle gap; "Confirmed" for a gap
that also requires displacement (an "outside print") on both
sides of the gap, a stricter variant.
h0 (float): Current candle's high.
h2 (float): Two candles back's high.
l0 (float): Current candle's low.
l2 (float): Two candles back's low.
c0 (float): Current candle's close.
c1 (float): One candle back's close.
c2 (float): Two candles back's close.
o0 (float): Current candle's open.
o1 (float): One candle back's open.
o2 (float): Two candles back's open.
minGap (float): Minimum required gap size, in price units.
Returns: [isUp, isDown, upTop, upBot, downTop, downBot]
buildZone(top, bot, formTime, confTime, hourEnd, isUp, isLast, zoneColor, showMid, midColor, midStyle)
Draws a zone box (and optional midline) and returns the
populated Zone object.
Parameters:
top (float): The zone's upper boundary.
bot (float): The zone's lower boundary.
formTime (int): Bar time the zone formed.
confTime (int): Bar time the zone was confirmed.
hourEnd (int): Caller-defined expiry time for the zone.
isUp (bool): True if this is an upward (bullish) zone.
isLast (bool): Caller-defined flag, passed straight through to the Zone.
zoneColor (color): The resolved color for the box (and border).
showMid (bool): Whether to also draw a midline through the zone's center.
midColor (color): Color for the midline, if drawn.
midStyle (string): Line style for the midline: "Solid", "Dotted", or "Dashed".
Returns: The newly created Zone.
Zone
Represents a detected price-gap zone and its drawn chart objects.
Fields:
mainBox (series box): The zone's drawn box.
midLine (series line): Optional midline through the zone's center.
boxLabel (series label): Optional label attached to the zone.
overlayBox (series box): Optional secondary box (e.g. for partial-fill shading).
top (series float): The zone's upper boundary.
bot (series float): The zone's lower boundary.
formationTime (series int): The bar time the zone formed.
confirmTime (series int): The bar time the zone was confirmed.
hourEnd (series int): A caller-defined expiry time for the zone.
isFilled (series bool): Whether the zone has been fully filled/mitigated.
wasHit (series bool): Whether price has touched the zone at all.
isProcessed (series bool): Internal bookkeeping flag for caller use.
isLast (series bool): Caller-defined flag (e.g. "most recent of its kind").
isBull (series bool): True if the zone is an upward (bullish) gap.
isFlipped (series bool): Whether the zone has flipped direction (price closed
fillProgress (series float): Tracks how far into the zone price has intruded.
Generic 3-candle price-gap zone detection and drawing utilities.
Detects a gap between two candle extremes separated by one middle
candle, with an optional stricter mode requiring displacement on
both sides of the gap. Builds a box (and optional midline) to
represent the zone once detected.
scanZone(mode, h0, h2, l0, l2, c0, c1, c2, o0, o1, o2, minGap)
Scans three consecutive candles for a price-gap zone in either
direction.
Parameters:
mode (string): "Standard" for a plain 3-candle gap; "Confirmed" for a gap
that also requires displacement (an "outside print") on both
sides of the gap, a stricter variant.
h0 (float): Current candle's high.
h2 (float): Two candles back's high.
l0 (float): Current candle's low.
l2 (float): Two candles back's low.
c0 (float): Current candle's close.
c1 (float): One candle back's close.
c2 (float): Two candles back's close.
o0 (float): Current candle's open.
o1 (float): One candle back's open.
o2 (float): Two candles back's open.
minGap (float): Minimum required gap size, in price units.
Returns: [isUp, isDown, upTop, upBot, downTop, downBot]
buildZone(top, bot, formTime, confTime, hourEnd, isUp, isLast, zoneColor, showMid, midColor, midStyle)
Draws a zone box (and optional midline) and returns the
populated Zone object.
Parameters:
top (float): The zone's upper boundary.
bot (float): The zone's lower boundary.
formTime (int): Bar time the zone formed.
confTime (int): Bar time the zone was confirmed.
hourEnd (int): Caller-defined expiry time for the zone.
isUp (bool): True if this is an upward (bullish) zone.
isLast (bool): Caller-defined flag, passed straight through to the Zone.
zoneColor (color): The resolved color for the box (and border).
showMid (bool): Whether to also draw a midline through the zone's center.
midColor (color): Color for the midline, if drawn.
midStyle (string): Line style for the midline: "Solid", "Dotted", or "Dashed".
Returns: The newly created Zone.
Zone
Represents a detected price-gap zone and its drawn chart objects.
Fields:
mainBox (series box): The zone's drawn box.
midLine (series line): Optional midline through the zone's center.
boxLabel (series label): Optional label attached to the zone.
overlayBox (series box): Optional secondary box (e.g. for partial-fill shading).
top (series float): The zone's upper boundary.
bot (series float): The zone's lower boundary.
formationTime (series int): The bar time the zone formed.
confirmTime (series int): The bar time the zone was confirmed.
hourEnd (series int): A caller-defined expiry time for the zone.
isFilled (series bool): Whether the zone has been fully filled/mitigated.
wasHit (series bool): Whether price has touched the zone at all.
isProcessed (series bool): Internal bookkeeping flag for caller use.
isLast (series bool): Caller-defined flag (e.g. "most recent of its kind").
isBull (series bool): True if the zone is an upward (bullish) gap.
isFlipped (series bool): Whether the zone has flipped direction (price closed
fillProgress (series float): Tracks how far into the zone price has intruded.
Phát hành các Ghi chú
v2Added:
trendStack(src, len1, len2, len3, len4)
Checks whether price sits above (or below) a stack of EMAs of
increasing length, a simple multi-timeframe trend alignment
filter.
Parameters:
src (float): The source series to compare against the EMA stack (e.g. hl2).
len1 (simple int): Length of the shortest EMA.
len2 (simple int): Length of the second EMA.
len3 (simple int): Length of the third EMA.
len4 (simple int): Length of the longest EMA.
Returns: [uptrend, downtrend, ema1, ema2, ema3, ema4] -- uptrend is true
when src is above all four EMAs, downtrend when it's below all
four. The individual EMA values are also returned for plotting
or further use by the caller.
pivotAvg(len)
Tracks a pivot-based upper/lower band pair and their midpoint,
stepping incrementally toward each new pivot high/low as it forms.
Parameters:
len (int): Lookback length for the highest-high / lowest-low pivot check.
Returns: [upper, lower, mid, dir] -- dir is 1 just after a new pivot high,
-1 just after a new pivot low, and holds its last value otherwise.
rollingAvg(src, windowMs, minBars)
Computes a rolling volume-weighted average of a source series
over a trailing time window, along with its variance and
standard deviation.
Parameters:
src (float): The source series (e.g. close).
windowMs (simple int): Trailing window size, in milliseconds.
minBars (simple int): Minimum number of bars required before the window is
considered valid.
Returns: [avg, variance, stDev]
Phát hành các Ghi chú
v3Added:
method update(state, recentPH_Y, recentPH_X, recentPL_Y, recentPL_X, hi, lo, cl, idx)
Updates a ChochState with the current bar's data: tracks the
active leg's extremes and detects a Change of Character (CHoCH)
-- a close beyond the last confirmed opposing swing point.
Namespace types: ChochState
Parameters:
state (ChochState): The ChochState to update. Create one with ChochState.new()
and hold it in a `var` at the call site so it persists across bars.
recentPH_Y (float): Most recent confirmed swing-high price (na if none yet).
recentPH_X (int): Bar index of recentPH_Y.
recentPL_Y (float): Most recent confirmed swing-low price (na if none yet).
recentPL_X (int): Bar index of recentPL_Y.
hi (float): Current bar's high.
lo (float): Current bar's low.
cl (float): Current bar's close.
idx (int): Current bar's index.
Returns: [isBullChoCh, isBearChoCh] -- true on the bar a CHoCH is
detected in that direction, false otherwise. When either is
true, the caller should also treat its own swing-break
tracking (e.g. "has this pivot already been broken") as reset,
since the leg just changed direction.
ChochState
Tracks market-structure trend state for Change-of-Character (CHoCH)
Fields:
trend (series int): Current trend direction: 1 = bullish, -1 = bearish, 0 = not
extremeHighY (series float): The highest high reached during the current leg.
extremeHighX (series int): The bar index of extremeHighY.
extremeLowY (series float): The lowest low reached during the current leg.
extremeLowX (series int): The bar index of extremeLowY.
startX (series int): Bar index anchor for the current leg.
startY (series float): Price anchor for the current leg.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.