Library/Price Action and Candlesticks/Candlestick Scanning and Context/Trend, Volatility, and Volume Pattern Context

D06-F05-A06 / Complete engineering topic

Trend, Volatility, and Volume Pattern Context

A production-minded guide to Trend, Volatility, and Volume Pattern Context.

Trend, Volatility, and Volume Pattern ContextD06 / D06-F05

Candlestick scanners become difficult to trust when a pattern name is the only evidence they return. This tutorial builds the missing contract around one question: What causal trend, range, and activity conditions surrounded the occurrence? By the end, you can derive three separately auditable context features from prior closes, ranges, and volumes plus the current closed bar and verify the same result in Python and TypeScript.

Begin with the decision, not the chart decoration

Each dimension keeps its own diagnostic. Combining them happens later, so a large-volume bar cannot silently compensate for wrong trend direction or zero volatility scale. TA-Lib’s official catalog demonstrates that many candlestick detectors can share an OHLC-array interface, while its API supports both whole-array and streaming execution (function catalog, core API). Our task is not to imitate undocumented vendor settings. It is to make the scanner boundary observable.

The selected formula is:

slope=Ct1Ctn(n1)median(R),vr=Rt/median(R),qr=Vt/median(V)slope=\frac{C_{t-1}-C_{t-n}}{(n-1)\,median(R)},\quad v_r=R_t/median(R),\quad q_r=V_t/median(V)

The comparison is inclusive, the remaining tie-breaks are stable, and unavailable evidence never becomes a convenient zero. Those are implementation choices. They make behavior testable; they do not prove a market edge.

Follow the data contract

The canonical input and output tables live in the topic README. Preserve source-qualified instrument identity, interval and session, price basis, detector version, event time, availability time, and closed-bar state. Binance’s official kline stream shows why finality must be explicit: its payload distinguishes an updating bar from a closed one (provider schema). The exact fields differ across providers, so adapt at ingestion and keep the algorithm provider-neutral.

Rendering system map…

What to notice: validation and time eligibility happen before the decision. A plausible pattern found with later information is still invalid for a point-in-time scan.

Trend, Volatility, and Volume Pattern Context worked decision

Open the accessible full-size diagram. The guided lab lets you step through canonical, equality-boundary, and rejected states with reduced-motion support.

Recalculate the fixture

Prior closes fall 105→101 over four steps while median range is 2: normalized slope is −0.5. Current range and volume ratios are 1.5; the three feature scores are 0.5, 0.75, and 1.0. This is labeled synthetic teaching data. The stored expected values were frozen independently of either implementation; both languages must match them within 1e-9 for numbers and exactly for identifiers, arrays, booleans, reason codes, and states.

Implement one source of scanner semantics

The topic-specific Python and TypeScript entry points delegate to a shared D06-F05 family core. That architecture prevents nine packages from inventing nine versions of finite-number checks, inclusive boundaries, and error semantics. It does not hide the topic algorithm: each public wrapper names exactly one core function, and the canonical README freezes its behavior before derivatives.

Run the Python test with python tests/test_trend_volatility_volume_context.py and the TypeScript test with node --test tests/trend_volatility_volume_context.test.ts from the topic folder. The shared fixture is the cross-language oracle.

Interpret the result carefully

A detector can match geometry, the context can score highly, confirmation can occur, and the ranked alert can still lose money. Lo, Mamaysky, and Wang’s computational work is useful here because it separates systematic recognition from an empirical evaluation design (NBER Working Paper 7613). A production claim needs point-in-time universe membership, survivorship controls, costs, multiple-testing controls, out-of-sample data, and uncertainty. This tutorial claims only reproducible infrastructure behavior.

Failure checklist

  • Reject provisional terminal bars and future-known levels.
  • Do not mix raw and adjusted prices or incompatible session calendars.
  • Preserve warm-up, zero-scale, invalid, suppressed, and expired states.
  • Version definitions before changing thresholds or precedence.
  • Keep ranking scores distinct from probabilities and expected returns.
  • Retain reason codes so an operator can explain every accepted or rejected event.

What comes next

Continue through the related topics listed in the canonical package. Together the family moves from a stable detector registry to occurrence evidence, causal scanning, context, conflict handling, confirmation, and final ranked deduplicated output. Full sources and applicability boundaries are in REFERENCES.md.

Decision flow

Purpose: show the causal position of Trend, Volatility, and Volume Pattern Context.

Rendering system map…

Takeaway: the output records both the decision and the evidence boundary.

ReferencesPrimary sources and evidence notes

Expand the source trail, evidence role, and limitations behind the engineering choices.

SRC-01 — TA-Lib function catalog and pattern-recognition group

  • Organization or authors: TA-Lib project
  • Source type: Official maintained function documentation
  • Publication or effective date: Continuously maintained
  • Version: Website state accessed 2026-08-01
  • URL or DOI: https://ta-lib.org/functions/
  • Accessed: 2026-08-01
  • Jurisdiction: Software documentation; not market regulation
  • Supports: Pattern recognition is a distinct function category; documented functions consume OHLC arrays and may be dispatched programmatically.
  • Limitations: TA-Lib's names and outputs do not define this package's registry metadata, thresholds, scores, conflict policy, or state machine.

SRC-02 — TA-Lib C/C++ Core API

  • Organization or authors: TA-Lib project
  • Source type: Official API documentation
  • Publication or effective date: Continuously maintained
  • Version: Website state accessed 2026-08-01
  • URL or DOI: https://ta-lib.org/api/
  • Accessed: 2026-08-01
  • Jurisdiction: Software documentation
  • Supports: The library distinguishes batch array processing, streaming, and dynamic abstraction-layer dispatch.
  • Limitations: This family is dependency-free and does not claim TA-Lib numerical parity.

SRC-03 — Binance Spot kline/candlestick stream

  • Organization or authors: Binance
  • Source type: Official provider API documentation
  • Publication or effective date: Continuously maintained
  • Version: Website state accessed 2026-08-01
  • URL or DOI: https://developers.binance.com/docs/binance-spot-api-docs/web-socket-streams#klinecandlestick-streams-for-utc
  • Accessed: 2026-08-01
  • Jurisdiction: Provider-specific spot-market data
  • Supports: A provider kline message can expose open/close times, OHLC, volume, trade counts, and an explicit closed-bar flag.
  • Limitations: Field meaning, interval calendars, revision behavior, and licensing are provider-specific; the synthetic fixture is not Binance market data.

SRC-04 — CME Group chart types and support/resistance lessons

  • Organization or authors: CME Group
  • Source type: Official exchange education
  • Publication or effective date: Continuously maintained
  • Version: Website state accessed 2026-08-01
  • URL or DOI: https://www.cmegroup.com/education/courses/technical-analysis/chart-types-candlestick-line-bar
  • Accessed: 2026-08-01
  • Jurisdiction: General market education
  • Supports: Candlesticks encode OHLC and practitioners commonly interpret them with trend, volume, support, and resistance context.
  • Limitations: Educational descriptions do not prescribe universal detector thresholds or validate forecasting value.

SRC-05 — Foundations of Technical Analysis

  • Organization or authors: Andrew W. Lo, Harry Mamaysky, and Jiang Wang
  • Source type: Original academic working paper and Journal of Finance article
  • Publication or effective date: 2000
  • Version: NBER Working Paper 7613
  • URL or DOI: https://doi.org/10.3386/w7613
  • Accessed: 2026-08-01
  • Jurisdiction: Empirical U.S. equities study for its declared historical sample
  • Supports: Subjective chart recognition can be translated into systematic computational rules; empirical usefulness requires a separate study design.
  • Limitations: It does not validate this family’s candlestick rules, weights, universe, or current predictive performance.

Evidence and licensing boundary

The external sources support data fields, software organization, common contextual concepts, and the need for systematic definitions. Every numeric weight, inclusive comparison, tie-break, expiry rule, and synthetic value in this package is an implementation choice or author-derived calculation. The fixtures are synthetic and CC0-1.0; no provider observations are redistributed.

trend_volatility_volume_context.ts
/** Topic entry point for Trend, Volatility, and Volume Pattern Context. */
export { trendVolatilityVolumeContext } from "../../../f05Core.ts";
import { trendVolatilityVolumeContext } from "../../../f05Core.ts";
export function calculateTopic(data: Record<string, unknown>) { return trendVolatilityVolumeContext(data); }
Full-height labplaygroundOpen full screen