fintech-algorithms

Scale-Aware Body Classification

Install and import

bash
npm install fintech-algorithms
ts
import { classifyBody } from "fintech-algorithms/price-action-and-candlesticks/candle-foundations/scale-aware-body-classification";

Signature

classifyBody(observation, priorClosedBodies, configInput)

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

observation
{
  "timestamp": "2026-01-05T10:25:00Z",
  "instrument_id": "SYNTH:ABC",
  "interval": "5m",
  "body": 4,
  "range": 6,
  "is_closed": true,
  "price_basis": "raw",
  "session": "continuous"
}
priorClosedBodies
[1, 2, 2, 3, 12]
configInput
{
  "window": 5,
  "min_periods": 5,
  "tick_size": 0.01,
  "thresholds": {
    "tiny_max": 0.25,
    "small_max": 0.75,
    "long_min": 1.5
  }
}

Call

classifyBody(observation, priorClosedBodies, configInput)

Returns

object with 23 fields: timestamp, instrument_id, interval, body, range, is_closed, price_basis, session, …

{
  "timestamp": "2026-01-05T10:25:00Z",
  "instrument_id": "SYNTH:ABC",
  "interval": "5m",
  "body": 4,
  "range": 6,
  "is_closed": true,
  "price_basis": "raw",
  "session": "continuous",
  "status": "ready",
  "body_class": "long",
  "body_score": 2,
  "raw_scale": 2,
  "effective_scale": 2,
  "scale_floor_applied": false
}

Showing 14 of 23 fields.

Other exports

This module also exports classifyBodySeries. 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

Scale-Aware Body Classification — body scale classification
Scale-Aware Body Classification — mean vs median

Calculation flow

Causal window lifecycle
sequenceDiagram
    participant Feed as Ordered candle feed
    participant A01 as A01 anatomy
    participant A02 as A02 classifier
    participant H as Closed-body history

    Feed->>A01: Closed candle t
    A01->>A02: body and range
    A02->>H: Read prior closed bodies only
    H-->>A02: causal reference window
    A02-->>Feed: classification for t
    A02->>H: Append body t after classification

    Feed->>A01: Open candle t+1 update
    A01->>A02: provisional body and range
    A02->>H: Read unchanged closed history
    H-->>A02: same causal reference window
    A02-->>Feed: provisional classification
    Note over A02,H: Open body is not appended
Classification flow
flowchart TD
    A["Receive validated A01 body and range"] --> B["Select last W prior closed bodies"]
    B --> C{"History count at least M?"}
    C -->|"No"| D["Return warmup: scale, score, class = null"]
    C -->|"Yes"| E["Compute median raw scale S"]
    E --> F["Apply optional tick floor: E = max(S, tick)"]
    F --> G{"Effective scale E greater than 0?"}
    G -->|"No"| H["Return zero_scale: score, class = null"]
    G -->|"Yes"| I["Compute q = current body / E"]
    I --> J{"Threshold interval"}
    J -->|"q <= 0.25"| K["tiny"]
    J -->|"0.25 < q <= 0.75"| L["small"]
    J -->|"0.75 < q < 1.50"| M["normal"]
    J -->|"q >= 1.50"| N["long"]

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