Create and store an alert. Generates a stable a_<n> id when init.id
is omitted. A supplied id wins as-is (used when restoring persisted
state) — the counter is advanced past any numeric a_<n> collision so a
later auto-generated id can't duplicate a restored one.
Evaluate every ACTIVE alert against a single close-price step
(prevPrice → newPrice) and return the ones that fired. Each fired
alert is flipped to active = false (one-shot) so it won't re-trigger
on later ticks until re-armed.
The input prices are never mutated. Triggering rules per condition:
crossing: prev and new straddle price (the products of the two
signed distances is negative), or new === price exactly.above: prev < price && new >= price.below: prev > price && new <= price.NaN inputs never trigger (all comparisons are false), so a malformed
tick is safely ignored rather than firing spuriously.
Remove every alert.
All alerts in insertion order (live references, not copies).
Remove an alert by id. Returns true if one was removed.
Re-arm (or disable) an alert by id. Re-arming a fired one-shot alert is how a host makes it triggerable again. Returns true if the alert exists.
StatictriggersPure predicate: does a prev → next price step satisfy condition
relative to level? Exposed as a static so tests and hosts can probe
the trigger logic without constructing a manager.
In-memory collection of price alerts with one-shot trigger evaluation (C3).
The manager is data-only: it owns no DOM and no rendering.
OHLCVChartdrives it from the realtime path — feeding each close-price step through check — and mirrors the active alerts to on-chart price lines.Ids are generated from a monotonically increasing counter (
a_0,a_1, …), matching the stable-counter scheme used elsewhere in the core (e.g.priceline:<n>) rather thanMath.random. This keeps ids deterministic across a session so tests and host code can rely on them.