fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Breakout and Retest Detection

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#

breakoutAndRetestDetection(input)

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

Parameters#

NameTypeNotes
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 }[] }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 , space .

Worked example#

executed 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
{
  "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#

breakoutAndRetestDetection(input)

Returns#

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

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

This module also 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.

Diagrams#

Breakout and Retest Detection — system map

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Level Confluence and Zone Scoring family#