PINE LIBRARY
업데이트됨 OriginLifecycle

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.
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.
릴리즈 노트
v2Added:
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
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.