fintech-algorithms

Support/Resistance Clustering

Install and import

bash
npm install fintech-algorithms
ts
import { clusterPivotLevels } from "fintech-algorithms/geometric-chart-patterns/pivots-and-levels/support-resistance-clustering";

Signature

clusterPivotLevels(pivots, epsBps, minTouches)

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

pivots
[
  {
    "kind": "high",
    "event_index": 0,
    "confirmation_index": 3,
    "price": 100
  },
  {
    "kind": "high",
    "event_index": 10,
    "confirmation_index": 13,
    "price": 100.3
  },
  {
    "kind": "high",
    "event_index": 20,
    "confirmation_index": 23,
    "price": 99.9
  }
]

Showing 3 of 4 elements.

epsBps
50
minTouches
3

Call

clusterPivotLevels(pivots, epsBps, minTouches)

Returns

object with 2 fields: clusters, noise

{
  "clusters": [
    {
      "kind": "high",
      "cluster_id": "high-0",
      "level": 100,
      "lower": 99.9,
      "upper": 100.3,
      "touch_count": 3,
      "first_confirmation_index": 3,
      "last_confirmation_index": 23,
      "member_event_indexes": [0, 10, 20]
    }
  ],
  "noise": [
    {
      "kind": "high",
      "event_index": 30,
      "confirmation_index": 33,
      "price": 105
    }
  ]
}

Other exports

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

Support/Resistance Clustering — failure atlas
Support/Resistance Clustering — family handoff
Support/Resistance Clustering — knowledge time
Support/Resistance Clustering — parameter boundary

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

  • A Density-Based Algorithm for Discovering Clusters in Large Spatial Databases with Noise — Martin Ester, Hans-Peter Kriegel, Jorg Sander, Xiaowei Xu
  • sklearn.cluster.DBSCAN — scikit-learn project
  • Pine Script Concepts: Repainting — TradingView