fintech-algorithms

Candle Anatomy

Install and import

bash
npm install fintech-algorithms
ts
import { analyzeCandle } from "fintech-algorithms/price-action-and-candlesticks/candle-foundations/candle-anatomy";

Signature

analyzeCandle(candle, directionEpsilon)

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

candle
{
  "timestamp": "2026-01-05T10:00:00Z",
  "instrument_id": "SYNTH:ABC",
  "interval": "5m",
  "open": 100,
  "high": 108,
  "low": 97,
  "close": 105,
  "is_closed": true,
  "volume": 1200,
  "price_basis": "raw-trades",
  "session": "synthetic-utc"
}
directionEpsilon
0

Call

analyzeCandle(candle, directionEpsilon)

Returns

object with 23 fields: open, high, low, close, timestamp, instrument_id, interval, is_closed, …

{
  "open": 100,
  "high": 108,
  "low": 97,
  "close": 105,
  "timestamp": "2026-01-05T10:00:00Z",
  "instrument_id": "SYNTH:ABC",
  "interval": "5m",
  "is_closed": true,
  "volume": 1200,
  "price_basis": "raw-trades",
  "session": "synthetic-utc",
  "body_high": 105,
  "body_low": 100,
  "body": 5
}

Showing 14 of 23 fields.

Other exports

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

Candle Anatomy — candle anatomy
Candle Anatomy — candle comparison

Calculation flow

Candle lifecycle and revision state
stateDiagram-v2
    [*] --> Collecting
    Collecting --> Provisional: first eligible price
    Provisional --> Provisional: new trade updates high, low, or close
    Provisional --> Closed: interval ends
    Closed --> Revised: provider correction
    Revised --> Closed: corrected OHLC republished
    Closed --> [*]
Candle anatomy calculation flow
flowchart TD
    A["Receive OHLC and metadata"] --> B{"All OHLC values finite?"}
    B -->|"No"| X["Reject with validation error"]
    B -->|"Yes"| C{"High and low contain open and close?"}
    C -->|"No"| X
    C -->|"Yes"| D["Compute body high and body low"]
    D --> E["Compute body, shadows, and range"]
    E --> F["Assign direction using epsilon"]
    F --> G{"Range greater than zero?"}
    G -->|"Yes"| H["Compute component ratios and positions"]
    G -->|"No"| I["Set ratios and positions to null"]
    H --> J["Return anatomy and metadata"]
    I --> J

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