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

Double Bottom

Install and import#

bash
npm install fintech-algorithms
ts
import { doubleBottom } from "fintech-algorithms/geometric-chart-patterns/reversal-structures/double-bottom";

Signature#

doubleBottom(close, params)

Double bottom detection: two comparable lows separated by a peak, confirmed on a close above the neckline. Chart patterns are usually described in prose vague enough to fit almost anything; encoding one forces a decision about how close "comparable" is and how much confirmation is required, and this returns those tolerances alongside the verdict. This topic wrapper accepts the close series and detection parameters, then delegates to the family detector core.

Parameters#

NameTypeNotes
closenumber[]Finite, strictly positive closes in chronological order.
paramsRecord<string, number>Optional pivot, geometry, prior-trend, and confirmation overrides; unknown keys are rejected.
optional

Returns#

{ pattern, state, reason, event, events, pivots, parameters }

A state rather than a boolean — searching, candidate, confirmed, or rejected — with the reason, the pivots that formed it, and the parameters in force. The parameters are the point: the same series yields a different answer under different tolerances, and a pattern reported without them cannot be reproduced.

Errors#

  • When close is empty, non-finite, zero, or negative — throws an Error
  • When a parameter is unknown or outside its accepted range — throws an Error
  • When a valid non-empty series has insufficient confirmed pivots — returns state searching rather than throwing

Complexity: time O(n), space O(pivots).

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#

close
[120, 119, 118, 117, 116, 115]

Showing 6 of 72 elements.

Call#

doubleBottom(close, params)

Returns#

object with 7 fields: pattern, state, reason, event, events, pivots, parameters

{
  "pattern": "double_bottom",
  "state": "confirmed",
  "reason": "neckline-break-confirmed",
  "event": {
    "pattern": "double_bottom",
    "pivot_indices": [14, 22, 30],
    "pivot_prices": [100, 110, 99],
    "pivot_types": ["low", "high", "low"],
    "candidate_available_index": 32,
    "confirmation_index": 40,
    "neckline": 110,
    "metrics": {
      "test_mean": 99.5,
      "level_spread": 0.010050251256281407,
      "retracement_min": 0.10552763819095477,
      "head_dominance": null,
      "formation_bars": 16,
      "min_separation": 8
    },
    "prior_move": 0.12,
    "state": "confirmed",
    "reason": "neckline-break-confirmed",
    "direction": "bullish"
  },
  "events": [
    {
      "pattern": "double_bottom",
      "pivot_indices": [14, 22, 30],
      "pivot_prices": [100, 110, 99],
      "pivot_types": ["low", "high", "low"],
      "candidate_available_index": 32,
      "confirmation_index": 40,
      "neckline": 110,
      "metrics": {
        "test_mean": 99.5,
        "level_spread": 0.010050251256281407,
        "retracement_min": 0.10552763819095477,
        "head_dominance": null,
        "formation_bars": 16,
        "min_separation": 8
      },
      "prior_move": 0.12,
      "state": "confirmed",
      "reason": "neckline-break-confirmed",
      "direction": "bullish"
    }
  ],
  "pivots": [
    {
      "kind": "low",
      "index": 14,
      "confirmation_index": 16,
      "price": 100
    },
    {
      "kind": "high",
      "index": 22,
      "confirmation_index": 24,
      "price": 110
    },
    {
      "kind": "low",
      "index": 30,
      "confirmation_index": 32,
      "price": 99
    }
  ],
  "parameters": {
    "pivot_left": 2,
    "pivot_right": 2,
    "min_swing_bars": 5,
    "max_pattern_bars": 40,
    "max_confirmation_bars": 15,
    "trend_lookback": 6,
    "level_tolerance": 0.025,
    "shoulder_tolerance": 0.025,
    "min_retracement": 0.05,
    "head_margin": 0.05,
    "min_prior_trend": 0.03,
    "break_buffer": 0
  }
}

Other exports#

This module also exports confirmedPivots, detectReversal, traceReversal. 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#

Double Bottom — double bottom anatomy

Calculation flow#

Double Bottom causal state flow
flowchart LR
  A["Finalized close arrives"] --> B["Update strict pivots after right-window delay"]
  B --> C{"Required sequence available?"}
  C -- "No" --> S["SEARCHING"]
  C -- "Yes" --> D{"Spacing, width, and prior trend pass?"}
  D -- "No" --> R["REJECTED with reason"]
  D -- "Yes" --> E{"Similarity, retracement, and dominance pass?"}
  E -- "No" --> R
  E -- "Yes" --> K["CANDIDATE: project neckline"]
  K --> N{"close above neckline within window?"}
  N -- "Yes" --> F["CONFIRMED bullish event"]
  N -- "Not yet" --> K
  N -- "Window expired" --> R

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#

  • Claim-to-source map

The rest of the Reversal Structures family#