@cmike444/supply-and-demand-zones
Version:
A library for identifying supply and demand zones in candlestick data.
35 lines (34 loc) • 1.96 kB
TypeScript
import { Candle, SupplyZone, DemandZone } from '../types';
/**
* Identifies all supply and demand zones in a given array of candles.
*
* Each zone receives a `confidence` score (0–1) built from seven equally-weighted factors:
*
* **Departure leg (×3 weight, computed per zone):**
* - **countFactor**: proportion of departure candles that are decisive or explosive.
* - **rangeFactor**: average departure candle range normalised by local ATR.
* - **volumeFactor**: departure volume relative to base volume (ratio / (ratio + 1)).
*
* **Structural context (×1 weight each, blended in `identifyZones`):**
* - **positionFactor**: higher for supply zones at elevated prices and demand zones at
* depressed prices — harder for the opposing side to push through.
* - **freshnessFactor**: 1.0 if price has never entered the zone since formation; 0.5 if
* price touched the proximal line but was repelled before the distal line.
* - **timeframeFactor**: log-normalised candle interval — 1m → 0.0, 1w → 1.0. Higher
* timeframe zones carry more institutional significance.
* - **rrScore**: departure-based risk/reward score. Measures how far price actually
* travelled during the departure leg relative to the zone width (stop distance).
* `min(departureExtent / stopDistance / 5, 1)` — a 5:1 R:R maps to 1.0. Also stored
* as a standalone `zone.rrScore` property for direct access when grading setups.
*
* Blend formula: `(departureScore × 3 + positionFactor + freshnessFactor + timeframeFactor) / 6`
* for the first six factors, then `(sixFactorScore × 6 + rrScore) / 7` to include the seventh,
* giving each of the seven factors equal weight (~14.3%).
*
* @param candles - An array of Candle objects to scan.
* @returns An object containing arrays of identified supply and demand zones.
*/
export declare function identifyZones(candles: Candle[]): {
supplyZones: SupplyZone[];
demandZones: DemandZone[];
};