Trend, Volatility, and Volume Pattern Context
Install and import#
npm install fintech-algorithmsimport { 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#
| Name | Type | Notes |
|---|---|---|
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#
{
"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#
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.
References#
- TA-Lib function catalog and pattern-recognition group — TA-Lib project
- TA-Lib C/C++ Core API — TA-Lib project
- Binance Spot kline/candlestick stream — Binance
- CME Group chart types and support/resistance lessons — CME Group
- Foundations of Technical Analysis — Andrew W. Lo, Harry Mamaysky, and Jiang Wang
- Evidence and licensing boundary