# Long-Legged Doji

`D06-F02-A10` · Price Action and Candlesticks → Single-Candle Patterns · archetype `record-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/single-candle-patterns/long-legged-doji/
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 { longLeggedDoji } from "fintech-algorithms/price-action-and-candlesticks/single-candle-patterns/long-legged-doji";
```

## Signature

```ts
longLeggedDoji(input)
```

Marks each bar whose body is a small fraction of its high-low span while both shadows are long, and reports how much slack the tightest of those three tests had.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `input` | `TopicInput` | yes | `bars` is a chronologically ordered array of OHLCV rows; each needs a non-empty `timestamp` strictly greater than the previous row's and finite `open`, `high`, `low`, `close` and `volume`. The single-candle family validates four `parameters` keys on every call: `body_ratio` (default 0.05, within 0..1), `shadow_ratio` (default 0.35, within 0..1), `shadow_body_multiple` (default 2, at least 0) and `tick_tolerance` (default 0.01, at least 0). This topic reads `body_ratio` as the largest body share of the span it will accept and `shadow_ratio` as the smallest share of the span each shadow must reach. |

## Returns

`TopicResult`

`series.label` is `"neutral"` on a matching bar and `"none"` otherwise. `series.score` is the minimum of the three margins (`body_ratio` minus body share, upper-shadow share minus `shadow_ratio`, lower-shadow share minus `shadow_ratio`), so it is at or above zero exactly when the bar matches. `latest` carries the last value of each. There is no warm-up: both series are populated from the first bar, so `ready_at` is 0.

## Warm-up

The first `0 bars` positions are `null`. Every test is per-bar geometry with no smoothing state, so `label` and `score` are emitted for index 0 and `ready_at` is 0. The one gap is a flat bar where `high` equals `low`: `score` is null there and `label` is `"none"`, which is a real verdict rather than a warm-up placeholder.

## Errors

- When a bar has a non-finite price or volume, a negative volume, a `high` below its own open/low/close, a `low` above them, or a `timestamp` that does not advance — throws Error
- When `body_ratio` or `shadow_ratio` is not a finite number, or falls outside 0..1 — throws Error
- When `input` is not an object, `input.parameters` is not an object, or `bars` is not an array holding at least one bar — throws Error

## Complexity

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

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

`input`:

```json
{
  "bars": [
    {
      "timestamp": "2024-01-02",
      "basis": "synthetic-unadjusted",
      "open": 100,
      "high": 101.45,
      "low": 98.695,
      "close": 100,
      "volume": 750000,
      "benchmark": 200
    },
    {
      "timestamp": "2024-01-03",
      "basis": "synthetic-unadjusted",
      "open": 101.49111452,
      "high": 103.38381693,
      "low": 100.05480022,
      "close": 101.78791214,
      "volume": 795117,
      "benchmark": 200.56326135
    },
    {
      "timestamp": "2024-01-04",
      "basis": "synthetic-unadjusted",
      "open": 102.45519048,
      "high": 104.6701838,
      "low": 100.91147007,
      "close": 102.9549389,
      "volume": 840234,
      "benchmark": 201.11020913
    }
  ],
  "parameters": {}
}
```

### Call

```ts
longLeggedDoji(input)
```

### Returns

object with 9 fields: topic_id, title, state, ready, ready_at, series, latest, parameters, …

```json
{
  "topic_id": "D06-F02-A10",
  "title": "Long-Legged Doji",
  "state": "calculated",
  "ready": true,
  "ready_at": 0,
  "series": {
    "label": ["neutral", "none", "none", "none", "none", "neutral"],
    "score": [
      0.05,
      -0.03915474022958794,
      -0.08295729760191171,
      -0.08829149989844472,
      -0.0589777590581788,
      0.0044297342216514934
    ]
  },
  "latest": {
    "label": "none",
    "score": -0.06921211954649767
  },
  "parameters": {},
  "diagnostics": {
    "causal": true,
    "input_count": 96
  }
}
```

## Verification and provenance

Tier: **verified** (via E).

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.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/single-candle-patterns/long-legged-doji/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/single-candle-patterns/long-legged-doji/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
