UNPKG

@cmike444/supply-and-demand-zones

Version:

A library for identifying supply and demand zones in candlestick data.

29 lines (28 loc) 1.75 kB
import { Candle } from '../types'; /** * Calculates a confidence score (0–1) for a zone based on the strength of the departure leg. * * The score is the average of three equally-weighted factors: * * - **countFactor**: proportion of departure candles that are decisive or explosive in the * departure direction. A higher proportion signals a wall of unfilled orders behind the zone. * * - **rangeFactor**: average candle range of the departure leg normalised by `localATR`, * clamped to [0, 1]. Large candles relative to volatility indicate institutional conviction. * Falls back to 0.5 when `localATR` is zero (insufficient data). * * - **volumeFactor**: average departure volume relative to average base volume, mapped through * `ratio / (ratio + 1)` so that higher volume always increases confidence asymptotically toward 1. * Sparse or declining departure volume scores below 0.5. Falls back to 0.5 when volume data is * absent or base volume is zero. * * - **timeFactor**: encodes the "Time at Level" odds-enhancer from the spec. Fewer base candles * imply a sharper, less-disputed imbalance. 1–3 candles → 1.0; 4–6 candles → 0.5. * * @param departureCandles - Candles forming the explosive leg away from the zone. * @param baseCandles - Candles forming the indecisive base of the zone. * @param localATR - ATR computed for the context window around the zone. * @param isUpwardDeparture - `true` for a bullish departure (demand zone), `false` for bearish (supply zone). * @returns A confidence score in the range [0, 1]. */ export declare function calculateConfidence(departureCandles: Candle[], baseCandles: Candle[], localATR: number, isUpwardDeparture: boolean): number;