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

Support/Resistance Pattern Context

Install and import#

bash
npm install fintech-algorithms
ts
import { supportResistanceContext } from "fintech-algorithms/price-action-and-candlesticks/candlestick-scanning-and-context/support-resistance-pattern-context";

Signature#

supportResistanceContext(data)

select the nearest causally confirmed directional level and turn ATR-normalized distance into a transparent [0,1] context feature.

Parameters#

NameTypeNotes
data{ pattern_price: number; atr: number; direction: string; occurrence_index: number; max_distance_atr: number; levels: { price: number; kind: string; strength: number; confirmed_index: number }[] }Topic input record; the required fields are fixed by this topic data-contract.

Returns#

{ state, context_score, matched_level, target_kind?, distance_atr? }

One directional context record. state is ready, no-causal-level, or unsupported-direction; score and distance are present only when their evidence exists.

Complexity: time O(n log n) worst case; see README for topic-specific n, space O(n).

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

data
{
  "pattern_price": 100,
  "atr": 2,
  "direction": "bullish",
  "occurrence_index": 10,
  "max_distance_atr": 2,
  "levels": [
    {
      "price": 99,
      "kind": "support",
      "strength": 0.8,
      "confirmed_index": 9
    },
    {
      "price": 101,
      "kind": "resistance",
      "strength": 0.9,
      "confirmed_index": 8
    },
    {
      "price": 100.2,
      "kind": "support",
      "strength": 1,
      "confirmed_index": 11
    }
  ]
}

Call#

supportResistanceContext(data)

Returns#

object with 4 fields: state, target_kind, distance_atr, context_score

{
  "state": "ready",
  "target_kind": "support",
  "distance_atr": 0.5,
  "context_score": 0.75
}

Diagrams#

Support/Resistance Pattern Context — decision

Calculation flow#

Decision flow
flowchart LR
    A["Validated point-in-time input"] --> B["Choose direction-relevant level kind"]
    B --> C["Remove future-confirmed levels"]
    C --> D{"Boundary satisfied?"}
    D -->|"Yes"| E["Reason-coded ready output"]
    D -->|"No"| F["Explicit rejected or unavailable state"]

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 Candlestick Scanning and Context family#