OriginLifecycleLibrary "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)
prevH (array)
prevL (array)
prevC (array)
prevT (array)
currO (array)
currH (array)
currL (array)
currC (array)
currT (array)
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) : 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) : The per-pattern candidate array to update.
ltfMin (int) : The LTF length this buffer represents; candidates with a
different ltfMinutes are skipped.
prevO (array)
prevH (array)
prevL (array)
prevC (array)
prevT (array)
currO (array)
currH (array)
currL (array)
currC (array)
currT (array)
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) : Per-pattern origin-candidate array.
greedyEntries (array) : Per-pattern greedy-entry price array.
greedyConsumedFlags (array) : 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.
Pine Script®库






















