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

Trend, Volatility, and Volume Pattern Context

Install and import#

bash
npm install fintech-algorithms
ts
import { trendVolatilityVolumeContext } from "fintech-algorithms/price-action-and-candlesticks/candlestick-scanning-and-context/trend-volatility-and-volume-pattern-context";

Signature#

trendVolatilityVolumeContext(data)

derive three separately auditable context features from prior closes, ranges, and volumes plus the current closed bar.

Parameters#

NameTypeNotes
data{ prior_closes: number[]; prior_ranges: number[]; prior_volumes: number[]; lookback: number; expected_prior_trend: string; current_range: number; current_volume: number; target_volume_ratio: number }Topic input record; the required fields are fixed by this topic data-contract.

Returns#

{ state, history_count?, range_scale?, volume_scale?, normalized_slope?, trend_score?, volatility_ratio?, volatility_score?, volume_ratio?, volume_score? }

One readiness record. state is warmup until lookback aligned observations exist, zero-scale for unusable range or volume scales, and ready with the three component scores otherwise; no positional series is returned.

Warm-up#

The first lookback aligned observations positions are state: warmup. The function returns one readiness record until aligned close, range, and volume histories reach lookback; it does not emit a positional null prefix.

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
{
  "prior_closes": [105, 104, 103, 102, 101],
  "prior_ranges": [2, 2, 2, 2, 2],
  "prior_volumes": [100, 100, 100, 100, 100],
  "lookback": 5,
  "expected_prior_trend": "downtrend",
  "current_range": 3,
  "current_volume": 150,
  "target_volume_ratio": 1.5
}

Call#

trendVolatilityVolumeContext(data)

Returns#

object with 7 fields: state, normalized_slope, trend_score, volatility_ratio, volatility_score, volume_ratio, volume_score

{
  "state": "ready",
  "normalized_slope": -0.5,
  "trend_score": 0.5,
  "volatility_ratio": 1.5,
  "volatility_score": 0.75,
  "volume_ratio": 1.5,
  "volume_score": 1
}

Diagrams#

Trend, Volatility, and Volume Pattern Context — decision

Calculation flow#

Decision flow
flowchart LR
    A["Validated point-in-time input"] --> B["Require causal warm-up"]
    B --> C["Compute robust prior scales"]
    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#