# Trend, Volatility, and Volume Pattern Context

`D06-F05-A06` · Price Action and Candlesticks → Candlestick Scanning and Context · archetype `record-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/candlestick-scanning-and-context/trend-volatility-and-volume-pattern-context/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## 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

```ts
trendVolatilityVolumeContext(data)
```

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

## Parameters

| Name | Type | Required | 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 }` | yes | 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

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`data`:

```json
{
  "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

```ts
trendVolatilityVolumeContext(data)
```

### Returns

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

```json
{
  "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
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.12.0.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/price-action-and-candlesticks/candlestick-scanning-and-context/trend-volatility-and-volume-pattern-context/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/candlestick-scanning-and-context/trend-volatility-and-volume-pattern-context/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/price-action-and-candlesticks/llms.txt
