# Breakout and Retest Detection

`D08-F06-A08` · Geometric Chart Patterns → Level Confluence and Zone Scoring · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/geometric-chart-patterns/level-confluence-and-zone-scoring/breakout-and-retest-detection/
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 { breakoutAndRetestDetection } from "fintech-algorithms/geometric-chart-patterns/level-confluence-and-zone-scoring/breakout-and-retest-detection";
```

## Signature

```ts
breakoutAndRetestDetection(input)
```

Processes bars through breakout-pending, retest, confirmation, failure, and expiry states around one zone.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `input` | `{ zone_lower: number; zone_upper: number; break_buffer: number; retest_tolerance: number; breakout_closes: number; max_retest_bars: number; direction: string; bars: { high: number; low: number; close: number }[] }` | yes | Record containing zone bounds, buffers/tolerance, breakout close count, retest horizon, direction, and non-empty bars. |

## Returns

`{ state, confirmed, direction, breakout_index, retest_index, confirmation_index, transitions }`

One state-machine record with nullable event indexes and a complete transition trace; no positional warmup series is returned.

## Warm-up

The first `0` positions are `not emitted`. This state machine has no warm-up output: an empty bar set is rejected and valid observations begin in searching state rather than a positional warm-up series.

## Errors

- When zone, direction, buffer, count, horizon, or bar geometry input is invalid — throws

## Complexity

Time `undefined`, space `undefined`.

## 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
{
  "zone_lower": 99.5,
  "zone_upper": 100.5,
  "break_buffer": 0.2,
  "retest_tolerance": 0.15,
  "breakout_closes": 2,
  "max_retest_bars": 5,
  "direction": "up",
  "bars": [
    {
      "high": 100.5,
      "low": 99.8,
      "close": 100.2
    },
    {
      "high": 101,
      "low": 100.3,
      "close": 100.8
    },
    {
      "high": 101.3,
      "low": 100.7,
      "close": 101
    }
  ]
}
```

### Call

```ts
breakoutAndRetestDetection(input)
```

### Returns

object with 7 fields: state, confirmed, direction, breakout_index, retest_index, confirmation_index, transitions

```json
{
  "state": "confirmed",
  "confirmed": true,
  "direction": "up",
  "breakout_index": 2,
  "retest_index": 3,
  "confirmation_index": 4,
  "transitions": [
    {
      "index": 1,
      "from": "searching",
      "to": "breakout-pending",
      "close": 100.8
    },
    {
      "index": 2,
      "from": "breakout-pending",
      "to": "awaiting-retest",
      "close": 101
    },
    {
      "index": 3,
      "from": "awaiting-retest",
      "to": "retest-contact",
      "close": 100.7
    }
  ]
}
```

## Other exports

`calculate`, `priceByVolumeProfileConstruction`, `pocValueAreaHvnLvnDetection`, `fibonacciRetracementExtensionProjection`, `psychologicalRoundNumberLevelGeneration`, `multiSourceSupportResistanceZoneFusion`, `supportResistanceZoneStrengthDecayScoring`, `supportResistanceRoleReversalStateMachine`, `marketWideZoneProximityScannerRanking`. 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/geometric-chart-patterns/level-confluence-and-zone-scoring/breakout-and-retest-detection/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/geometric-chart-patterns/level-confluence-and-zone-scoring/breakout-and-retest-detection/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/geometric-chart-patterns/llms.txt
