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

Pivots and Levels

4 algorithms in Geometric Chart Patterns · 4 with asserted arithmetic.

In this family#

  1. Causal Pivot Detection verified

    Finds swing highs and lows using only bars that had already arrived. Most pivot code confirms a pivot with bars that come *after* it and then plots it at the earlier index — which is lookahead bias, and it is invisible on a chart.

    detectCausalPivots(bars, leftSpan, rightSpan, minSeparation)
  2. ZigZag Segmentation verified

    Segments a series into alternating swings that exceed a percentage threshold. Useful for structure, and routinely misused: the final swing is provisional and can be revised by the next bar.

    zigzagSegment(closes, threshold, minBars)
  3. Support/Resistance Clustering verified

    Groups nearby pivots into levels. Clustering in basis points rather than absolute price is what makes the result meaningful across instruments — a $1 band is noise on one stock and a whole level on another.

    clusterPivotLevels(pivots, epsBps, minTouches)
  4. Robust Trendline Fitting verified

    Fits a trendline through pivots in log space with outlier resistance. Log space matters: a straight line in price implies a constant *dollar* change per bar, which is not what a trend on a long chart means.

    fitRobustTrendline(pivots, kind, toleranceBps, minInliers, maxPoints)

What they share#

Every topic here is a row-classify</code> or <code>record-transform, so once you have called one the rest follow the same shape. Import paths differ only in the final segment:

ts
import { detectCausalPivots } from "fintech-algorithms/geometric-chart-patterns/pivots-and-levels/causal-pivot-detection";
import { zigzagSegment } from "fintech-algorithms/geometric-chart-patterns/pivots-and-levels/zigzag-segmentation";

Read them in the order above — the sequence is pedagogical, not alphabetical.

Where this sits#

Geometric Chart Patterns collects 27 algorithms across 4 families. For the concept behind this family rather than the call signatures, see the concept guides.