Candlestick Confirmation and Invalidation State Machine
Install and import#
npm install fintech-algorithmsimport { runConfirmationStateMachine } from "fintech-algorithms/price-action-and-candlesticks/candlestick-scanning-and-context/candlestick-confirmation-and-invalidation-state-machine";Signature#
runConfirmationStateMachine(data)advance directional candidates through closed-bar transitions with ordered levels, finite expiry, and complete reason-coded history.
Parameters#
| Name | Type | Notes |
|---|---|---|
data | { detection_index: number; direction: string; confirmation_level: number; invalidation_level: number; expires_after_bars: number; events: { bar_index: number; bar_closed: boolean; close: number }[] } | Topic input record; the required fields are fixed by this topic data-contract. |
Returns#
{ state, direction, confirmation_level, invalidation_level, transitions, terminal }
One lifecycle record. state progresses from awaiting-confirmation to confirmed, invalidated, or expired; terminal identifies those final states and transitions preserves the full reason-coded trace.
Complexity: time O(n log n) worst case; see README for topic-specific n,
space O(n).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"detection_index": 10,
"direction": "bullish",
"confirmation_level": 105,
"invalidation_level": 95,
"expires_after_bars": 3,
"events": [
{
"bar_index": 11,
"bar_closed": true,
"close": 102
},
{
"bar_index": 12,
"bar_closed": true,
"close": 106
}
]
}Call#
runConfirmationStateMachine(data)Returns#
object with 4 fields: state, terminal, confirmation_level, invalidation_level
{
"state": "confirmed",
"terminal": true,
"confirmation_level": 105,
"invalidation_level": 95
}Diagrams#
Calculation flow#
Decision flow
flowchart LR
A["Validated point-in-time input"] --> B["Detect geometry"]
B --> C["Arm ordered levels"]
C --> D{"Boundary satisfied?"}
D -->|"Yes"| E["Reason-coded ready output"]
D -->|"No"| F["Explicit rejected or unavailable state"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- TA-Lib function catalog and pattern-recognition group — TA-Lib project
- TA-Lib C/C++ Core API — TA-Lib project
- Binance Spot kline/candlestick stream — Binance
- CME Group chart types and support/resistance lessons — CME Group
- Foundations of Technical Analysis — Andrew W. Lo, Harry Mamaysky, and Jiang Wang
- Evidence and licensing boundary