Gap Classification
Install and import#
npm install fintech-algorithmsimport { gapClassification } from "fintech-algorithms/price-action-and-candlesticks/candle-foundations/gap-classification";Signature#
gapClassification(inputs)Classifies full-range, body, or opening gaps in either direction using an explicit tick-scaled minimum distance.
Parameters#
| Name | Type | Notes |
|---|---|---|
inputs | { previous: { open: number; high: number; low: number; close: number }; current: { open: number; high: number; low: number; close: number }; tick_size: number; minimum_gap_ticks: number } | Record containing previous, current, tick_size, and minimum_gap_ticks as defined by the topic data contract. |
Returns#
{ state, gap_direction, gap_type, gap_distance, threshold_distance, open_gap_up, open_gap_down, body_gap_up, body_gap_down, full_range_gap_up, full_range_gap_down, signed_open_gap, previous_close, current_open }
One classification record with state equal to gap or overlap, plus all directional checks and measured distances.
Errors#
- When either candle is invalid, tick_size is not positive, or minimum_gap_ticks is negative — throws
Complexity: time O(1),
space O(1).
Worked example#
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input#
{
"previous": {
"open": 100,
"high": 105,
"low": 99,
"close": 104
},
"current": {
"open": 106,
"high": 110,
"low": 106,
"close": 109
},
"tick_size": 1,
"minimum_gap_ticks": 1
}Call#
gapClassification(inputs)Returns#
object with 14 fields: state, gap_direction, gap_type, gap_distance, threshold_distance, open_gap_up, open_gap_down, body_gap_up, …
{
"state": "gap",
"gap_direction": "up",
"gap_type": "full-range",
"gap_distance": 1,
"threshold_distance": 1,
"open_gap_up": true,
"open_gap_down": false,
"body_gap_up": true,
"body_gap_down": false,
"full_range_gap_up": true,
"full_range_gap_down": false,
"signed_open_gap": 2,
"previous_close": 104,
"current_open": 106
}Other exports#
This module also exports
calculate, shadowToBodyRatio, trendContextFilter, doji, dragonflyDoji, gravestoneDoji, marubozu, spinningTop, hammer, hangingMan, invertedHammer, shootingStar, bullishEngulfing, bearishEngulfing, bullishHarami, bearishHarami, piercingLine, darkCloudCover, tweezerTop, tweezerBottom. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams#
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#
- Chart Types: Candlestick, Line, Bar — CME Group
- Candlestick chart — Nasdaq
- TA-Lib Pattern Recognition Functions — TA-Lib project
- Evidence boundary