# Shadow-to-Body Ratio

`D06-F01-A03` · Price Action and Candlesticks → Candle Foundations · archetype `record-transform` · difficulty 2/5 · verification **contract**

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

## Signature

```ts
shadowToBodyRatio(inputs)
```

Decomposes one OHLC candle and reports raw and tick-stabilized shadow-to-body ratios without hiding the zero-body case.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `inputs` | `{ candle: { open: number; high: number; low: number; close: number }; tick_size: number }` | yes | Record containing `candle` and positive `tick_size` fields as defined by the topic data contract. |

## Returns

`{ state, body, upper_shadow, lower_shadow, range, tick_size, effective_body, upper_to_body, lower_to_body, upper_to_effective_body, lower_to_effective_body, upper_to_range, lower_to_range, dominant_shadow, dominant_shadow_ratio }`

One diagnostic record. `state` is `calculated` for a nonzero body and `zero-body` when raw body ratios are undefined; no positional series is returned.

## Errors

- When the candle is invalid or tick_size is not positive — throws

## Complexity

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

## Worked example

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

`inputs`:

```json
{
  "candle": {
    "open": 100,
    "high": 105,
    "low": 97,
    "close": 102
  },
  "tick_size": 0.1
}
```

### Call

```ts
shadowToBodyRatio(inputs)
```

### Returns

object with 15 fields: state, body, upper_shadow, lower_shadow, range, tick_size, effective_body, upper_to_body, …

```json
{
  "state": "calculated",
  "body": 2,
  "upper_shadow": 3,
  "lower_shadow": 3,
  "range": 8,
  "tick_size": 0.1,
  "effective_body": 2,
  "upper_to_body": 1.5,
  "lower_to_body": 1.5,
  "upper_to_effective_body": 1.5,
  "lower_to_effective_body": 1.5,
  "upper_to_range": 0.375,
  "lower_to_range": 0.375,
  "dominant_shadow": "balanced"
}
```

Showing 14 of 15 fields.

## Other exports

`calculate`, `gapClassification`, `trendContextFilter`, `doji`, `dragonflyDoji`, `gravestoneDoji`, `marubozu`, `spinningTop`, `hammer`, `hangingMan`, `invertedHammer`, `shootingStar`, `bullishEngulfing`, `bearishEngulfing`, `bullishHarami`, `bearishHarami`, `piercingLine`, `darkCloudCover`, `tweezerTop`, `tweezerBottom`. 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: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

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

Generated from the docs.json payload shipped inside fintech-algorithms@0.12.0.
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/shadow-to-body-ratio/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/candle-foundations/shadow-to-body-ratio/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
