# Scale-Aware Body Classification

`D06-F01-A02` · Price Action and Candlesticks → Candle Foundations · archetype `row-classify` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/candle-foundations/scale-aware-body-classification/
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 { classifyBody } from "fintech-algorithms/price-action-and-candlesticks/candle-foundations/scale-aware-body-classification";
```

## Signature

```ts
classifyBody(observation, priorClosedBodies, configInput)
```

Classifies a candle body as long, short or doji **relative to recent bodies** rather than against a fixed threshold. A 50-point body is enormous on one instrument and unremarkable on another, so an absolute rule cannot transfer.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `observation` | `Observation` | yes | The candle's body and range, with its price basis and session. |
| `priorClosedBodies` | `number[]` | yes | Recent closed bodies forming the comparison distribution. Closed only — including the forming candle would let the present redefine its own context. |
| `configInput` | `{ window: number; min_periods: number; tick_size: number; thresholds: object }` | yes | `min_periods` refuses to classify until enough history exists, rather than judging against two candles. `tick_size` floors the comparison so sub-tick noise is not treated as structure. |

## Returns

`{ classification, percentile, window, min_periods, … }`

The classification with the distribution statistics behind it, so the same body can be seen to be long in one regime and short in another.

## Errors

- When fewer prior bodies are supplied than min_periods — reported as an unclassified state rather than thrown

## Complexity

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

## Worked example

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

### Input

`observation`:

```json
{
  "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`:

```json
[1, 2, 2, 3, 12]
```

`configInput`:

```json
{
  "window": 5,
  "min_periods": 5,
  "tick_size": 0.01,
  "thresholds": {
    "tiny_max": 0.25,
    "small_max": 0.75,
    "long_min": 1.5
  }
}
```

### Call

```ts
classifyBody(observation, priorClosedBodies, configInput)
```

### Returns

object with 9 fields: status, body_class, body_score, raw_scale, effective_scale, scale_floor_applied, history_count, body_to_current_range, …

```json
{
  "status": "ready",
  "body_class": "long",
  "body_score": 2,
  "raw_scale": 2,
  "effective_scale": 2,
  "scale_floor_applied": false,
  "history_count": 5,
  "body_to_current_range": 0.6666666666666666,
  "is_provisional": false
}
```

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

## 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/scale-aware-body-classification/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/candle-foundations/scale-aware-body-classification/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
