PINE LIBRARY
Cập nhật

OriginLifecycle

213
Library "OriginLifecycle"
Strict Highlander v7 origin lifecycle for engulfing indicators.
Exports enums, an OriginCandidate UDT, and four helper functions
used by engulfing_opportunities_v20.6+ to detect, track, promote,
invalidate, and consume origin levels discovered on lower
timeframes inside an engulfment zone.

Published-as-library rationale: the engulfing indicator is already at Pine v6's
top-level-declaration limit (CE10295). Moving these types and functions into a
library frees ~7 declarations in the main script without changing semantics.

Reference: highlander_v7.pine:212-293 for the state-transition rules this
implementation mirrors.

tickStateMachine(c, bO, bH, bL, bC, bTime)
  Pure state-transition function. One closed LTF bar in,
updated candidate out. Mirrors highlander_v7.pine:212-293.
  Parameters:
    c (OriginCandidate): The current candidate state.
    bO (float): Bar open.
    bH (float): Bar high.
    bL (float): Bar low.
    bC (float): Bar close.
    bTime (int): Bar start time in ms.
  Returns: Updated OriginCandidate with `lastProcessedTime := bTime`.
Caller is responsible for:
- Only passing CLOSED LTF bars.
- Skipping bars whose time <= c.lastProcessedTime.
- On BROKEN_BSUT, looking for a retest in subsequent bars to delete.

scanForBreakCandidates(isBullish, zoneLow, zoneHigh, prevO, prevH, prevL, prevC, prevT, currO, currH, currL, currC, currT, ltfValid, ltfMin, tfLabel, outCandidates)
  Find new BREAK pairs in the engulfment zone and push
them to `outCandidates` if not already tracked. De-dup
key is (price, createdTime, tfLabel).
  Parameters:
    isBullish (bool): true -> look for SUPPORT (green-green) pairs;
false -> look for RESISTANCE (red-red) pairs.
    zoneLow (float): Lower bound of the engulfment zone (inclusive).
    zoneHigh (float): Upper bound of the engulfment zone (inclusive).
    prevO (array<float>)
    prevH (array<float>)
    prevL (array<float>)
    prevC (array<float>)
    prevT (array<int>)
    currO (array<float>)
    currH (array<float>)
    currL (array<float>)
    currC (array<float>)
    currT (array<int>)
    ltfValid (bool): Pre-computed validity flag for this LTF.
    ltfMin (int): LTF length in minutes (baked into each new candidate).
    tfLabel (string): Display string, e.g. "1H".
    outCandidates (array<OriginCandidate>): The per-pattern candidate array to push into.
  Returns: Nothing (mutates outCandidates).

processNewLTFBars(candidates, ltfMin, prevO, prevH, prevL, prevC, prevT, currO, currH, currL, currC, currT, ltfValid)
  Drive the state machine across unprocessed LTF bars for every
candidate whose `ltfMinutes == ltfMin`. Removes candidates
that reach BROKEN_BSUT AND see a retest within the buffer.
  Parameters:
    candidates (array<OriginCandidate>): The per-pattern candidate array to update.
    ltfMin (int): The LTF length this buffer represents; candidates with a
different ltfMinutes are skipped.
    prevO (array<float>)
    prevH (array<float>)
    prevL (array<float>)
    prevC (array<float>)
    prevT (array<int>)
    currO (array<float>)
    currH (array<float>)
    currL (array<float>)
    currC (array<float>)
    currT (array<int>)
    ltfValid (bool): Validity flag.
  Returns: Nothing (mutates candidates).

applyConsumedOnTouch(candidates, greedyEntries, greedyConsumedFlags, isBullish, curLow, curHigh)
  Per-tick sweep. Marks CONFIRMED origins and
untouched greedy entries as consumed once price
wicks into them. Caller passes `curLow`/`curHigh`
because library functions cannot reference the
`low`/`high` chart globals directly.
  Parameters:
    candidates (array<OriginCandidate>): Per-pattern origin-candidate array.
    greedyEntries (array<float>): Per-pattern greedy-entry price array.
    greedyConsumedFlags (array<bool>): Parallel bool array — resized lazily to match
greedyEntries size.
    isBullish (bool): Drives the touch check for greedy entries
(origins use their own per-candidate dir).
    curLow (float): Current bar low (pass `low` from caller).
    curHigh (float): Current bar high (pass `high` from caller).
  Returns: Nothing (mutates both arrays).

OriginCandidate
  A single tracked origin candidate.
  Fields:
    tfLabel (series string): Display string ("1H", "5m" etc.).
    ltfMinutes (series int): Lower-timeframe length in minutes; used for the
    price (series float): The origin level price.
    dir (series OriginDir): UP (support) or DOWN (resistance).
    state (series OriginState): Current lifecycle state.
    firstTouchTime (series int): ms timestamp of first touch (0 if `touchSeen == false`).
    touchSeen (series bool): True once this candidate has been touched at least once.
    createdTime (series int): ms timestamp of the d1 bar that formed the BREAK pair.
    lastProcessedTime (series int): ms timestamp of the last LTF bar fed through the
    consecutiveDirCount (series int): Counter for 2-bar CONFIRMED confirmation, 0-2.
Phát hành các Ghi chú
v2

Added:
renderOriginLines(candidates, upColor, downColor, lineWidth)
  v2: Sync chart lines against candidate states. For every
CONFIRMED origin without a line, draws one at `c.price`
extending right. For every CONSUMED or BROKEN_BSUT origin
that has a line, deletes it and clears the reference.
Call once per pattern per bar (cheap — just reference
bookkeeping + occasional line.new / line.delete).
  Parameters:
    candidates (array<OriginCandidate>): Per-pattern origin-candidate array. Mutated.
    upColor (color): Line color for DIR_UP (support) origins.
    downColor (color): Line color for DIR_DOWN (resistance) origins.
    lineWidth (int): Line width (1-4).
  Returns: Nothing.

Updated:
OriginCandidate
  A single tracked origin candidate.
  Fields:
    tfLabel (series string): Display string ("1H", "5m" etc.).
    ltfMinutes (series int): Lower-timeframe length in minutes; used for the
    price (series float): The origin level price.
    dir (series OriginDir): UP (support) or DOWN (resistance).
    state (series OriginState): Current lifecycle state.
    firstTouchTime (series int): ms timestamp of first touch (0 if `touchSeen == false`).
    touchSeen (series bool): True once this candidate has been touched at least once.
    createdTime (series int): ms timestamp of the d1 bar that formed the BREAK pair.
    lastProcessedTime (series int): ms timestamp of the last LTF bar fed through the
    consecutiveDirCount (series int): Counter for 2-bar CONFIRMED confirmation, 0-2.
    lineRef (series line): v2: Chart line drawn at `price` once the state

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.