# Candle Anatomy

`D06-F01-A01` · Price Action and Candlesticks → Candle Foundations · archetype `record-transform` · difficulty 1/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/candle-foundations/candle-anatomy/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

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

## Signature

```ts
analyzeCandle(candle, directionEpsilon)
```

Decomposes one candle into body, upper and lower shadow, and direction. Every candlestick pattern is built on these measurements, so an inconsistent decomposition propagates into every pattern above it.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `candle` | `Candle` | yes | One OHLC candle with `is_closed`. An unclosed candle can still be analysed, but its body may yet change — the flag is carried through so downstream code can decide. |
| `directionEpsilon` | `number` | yes | How close open and close must be to count as unchanged rather than up or down. Without it, floating-point noise makes a doji impossible. · min: 0 |

## Returns

`{ open, high, low, close, body, upper_shadow, lower_shadow, direction, … }`

Every measurement a pattern rule needs, in price units.

## Errors

- When high is below low, or open or close falls outside the range — throws

## Complexity

Time `O(1)`, space `O(1)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`candle`:

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

`directionEpsilon`:

```json
0
```

### Call

```ts
analyzeCandle(candle, directionEpsilon)
```

### Returns

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

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

Showing 14 of 23 fields.

## Other 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.

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/price-action-and-candlesticks/candle-foundations/candle-anatomy/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/candle-foundations/candle-anatomy/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/price-action-and-candlesticks/llms.txt
