fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Belt Hold

Install and import#

bash
npm install fintech-algorithms
ts
import { beltHold } from "fintech-algorithms/price-action-and-candlesticks/single-candle-patterns/belt-hold";

Signature#

beltHold(input)

Marks each bar that opens at one extreme of its own range within a tick and closes at least 60 percent of the span away, and reports that body share and which side it favoured.

Parameters#

NameTypeNotes
inputTopicInputbars is a chronologically ordered array of OHLCV rows; each needs a non-empty timestamp strictly greater than the previous row's and finite open, high, low, close and volume. The single-candle family validates body_ratio (default 0.05), shadow_ratio (default 0.35), shadow_body_multiple (default 2) and tick_tolerance (default 0.01, at least 0) on every call, but this topic reads only tick_tolerance, how far the open may sit from the low (bullish) or the high (bearish). The 60 percent body share is fixed in the branch and is not configurable.

Returns#

TopicResult

series.label is "bullish" when the bar closes up and opens within tick_tolerance of its low, "bearish" when it closes down and opens within tick_tolerance of its high, and "none" otherwise. series.score is the body as a share of the high-low span, between 0 and 1, reported on every bar with a positive range whether or not it matched. latest carries the last value of each. There is no warm-up: both series are populated from the first bar, so ready_at is 0.

Warm-up#

The first 0 bars positions are null. Per-bar geometry with no smoothing state, so ready_at is 0. On a flat bar where high equals low the positive-span guard leaves score null and label at "none", which is a real verdict rather than a warm-up placeholder.

Errors#

  • When a bar has a non-finite price or volume, a negative volume, a high below its own open/low/close, a low above them, or a timestamp that does not advance — throws Error
  • When tick_tolerance is not a finite number or is negative — throws Error
  • When input is not an object, input.parameters is not an object, or bars is not an array holding at least one bar — throws Error

Complexity: time O(n), space O(n).

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#

input
{
  "bars": [
    {
      "timestamp": "2024-01-02",
      "basis": "synthetic-unadjusted",
      "open": 100,
      "high": 101.45,
      "low": 98.695,
      "close": 100,
      "volume": 750000,
      "benchmark": 200
    },
    {
      "timestamp": "2024-01-03",
      "basis": "synthetic-unadjusted",
      "open": 101.49111452,
      "high": 103.38381693,
      "low": 100.05480022,
      "close": 101.78791214,
      "volume": 795117,
      "benchmark": 200.56326135
    },
    {
      "timestamp": "2024-01-04",
      "basis": "synthetic-unadjusted",
      "open": 102.45519048,
      "high": 104.6701838,
      "low": 100.91147007,
      "close": 102.9549389,
      "volume": 840234,
      "benchmark": 201.11020913
    }
  ],
  "parameters": {}
}

Call#

beltHold(input)

Returns#

object with 9 fields: topic_id, title, state, ready, ready_at, series, latest, parameters, …

{
  "topic_id": "D06-F02-A13",
  "title": "Belt Hold",
  "state": "calculated",
  "ready": true,
  "ready_at": 0,
  "series": {
    "label": ["none", "none", "none", "none", "none", "none"],
    "score": [
      0,
      0.08915474022958794,
      0.13295729760191172,
      0.13829149989844472,
      0.1089777590581788,
      0.04557026577834851
    ]
  },
  "latest": {
    "label": "none",
    "score": 0.11921211954649767
  },
  "parameters": {},
  "diagnostics": {
    "causal": true,
    "input_count": 96
  }
}

Diagrams#

Belt Hold — article hero
Belt Hold — concept map
Belt Hold — decision comparison
Belt Hold — worked example

Calculation flow#

Belt Hold calculation flow
flowchart LR
    A["one closed OHLC candle, tick size, prior-only reference sc"] --> B["Validate order, basis, and finite values"]
    B --> C["Apply the selected Belt Hold convention"]
    C --> D["Emit value, readiness, and diagnostics"]
    D --> E["Interpret descriptively; test outcomes separately"]
    B -->|invalid or insufficient| X["Withhold output with a reason"]
Belt Hold readiness and evidence states
stateDiagram-v2
    [*] --> Waiting
    Waiting --> Ready: enough valid causal observations
    Waiting --> Rejected: malformed or unsupported input
    Ready --> Calculated: selected formula applied
    Calculated --> Interpreted: diagnostic and limitation retained
    Interpreted --> Ready: next observation arrives
    Rejected --> Waiting: corrected input and deterministic reset

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.

Read the article →

References#

  • TA-Lib pattern-recognition catalog — see linked primary or authoritative record
  • CME Group candlestick chart lesson — see linked primary or authoritative record
  • Japanese Candlestick Charting Techniques — see linked primary or authoritative record
  • Evidence decision
  • Level 1 evidence map

The rest of the Single-Candle Patterns family#