# Harami Cross

`D06-F03-A09` · Price Action and Candlesticks → Two-Candle Patterns · archetype `record-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/two-candle-patterns/harami-cross/
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 { haramiCross } from "fintech-algorithms/price-action-and-candlesticks/two-candle-patterns/harami-cross";
```

## Signature

```ts
haramiCross(input)
```

Scans consecutive pairs of bars for a doji whose body sits inside the previous bar's body, and reports the pattern's direction from the colour of that earlier bar.

## 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 pattern family validates two `parameters` keys on every call: `tick_tolerance` (default 0.01, at least 0) and `doji_body_ratio` (default 0.05, within 0..1). This topic uses both, `doji_body_ratio` as the largest body share of the second bar's span that still counts as a doji and `tick_tolerance` as the slack allowed at each end of the containment test. |

## Returns

`TopicResult`

`series.matched` is the boolean verdict for the pair ending at that index, and `series.label` is `"bullish"` when the first bar closed down, `"bearish"` when it closed up, and `"none"` when the pattern failed or the first bar closed exactly at its open. `latest` carries the last value of each. The warm-up is the one leading bar that has no predecessor.

## Warm-up

The first `1 bar` positions are `null`. The pattern needs a two-bar window, so both series hold null at index 0 and `ready_at` is 1. From index 1 onward `matched` is false or true, and false is a real verdict rather than a warm-up placeholder, so `ready_at` does not depend on any pattern ever firing. A one-bar input returns null throughout, with `ready_at` null and `state` "waiting".

## 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 `doji_body_ratio` is not a finite number or falls outside 0..1, or `tick_tolerance` is not a finite number or is negative — 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
haramiCross(input)
```

### Returns

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

```json
{
  "topic_id": "D06-F03-A09",
  "title": "Harami Cross",
  "state": "calculated",
  "ready": true,
  "ready_at": 1,
  "series": {
    "label": [null, "none", "none", "none", "none", "none"],
    "matched": [null, false, false, false, false, false]
  },
  "latest": {
    "label": "none",
    "matched": false
  },
  "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/two-candle-patterns/harami-cross/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/two-candle-patterns/harami-cross/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
