# Timeframes & Multi-Timeframe

> Timeframe-smart study defaults, automatic UTC VWAP anchoring, and the zero-adapter higher-timeframe candle pipeline.

Canonical page: [https://docs.kami.trade/engine/timeframes/](https://docs.kami.trade/engine/timeframes/)

Noise profiles, session boundaries, and structural swing spans vary dramatically between a `1m` scalp chart and a `1d` swing chart. Kami adapts study parameters, `VWAP` resets, and higher-timeframe projections automatically based on the active candle interval.

## Supported Intervals

| Interval | Duration (ms) | Parameter tier | Auto `VWAP` anchor | HTF targets (`HTF_MAP`) |
| --- | --- | --- | --- | --- |
| `1m` | `60,000` | Low (`<= 5m`) | Daily UTC (`00:00`) | `1h`, `1d` |
| `5m` | `300,000` | Low (`<= 5m`) | Daily UTC (`00:00`) | `1h`, `1d` |
| `15m` | `900,000` | Baseline | Daily UTC (`00:00`) | `4h`, `1d` |
| `1h` | `3,600,000` | Baseline | Daily UTC (`00:00`) | `4h`, `1d` |
| `4h` | `14,400,000` | Baseline | Weekly UTC (Mon `00:00`) | `1d` |
| `1d` | `86,400,000` | High (`>= 1d`) | Monthly UTC (1st `00:00`) | None (`[]`) |

## Timeframe-Smart Parameter Defaults

When you omit a parameter, `resolveParams()` checks `TF_DEFAULTS` for the chart's interval before falling back to the base default. **Explicit user or agent parameters always win** (`given[k] ?? tfDefault[k] ?? baseDefault`).

| Tier | Condition | Overridden parameters | Base default |
| --- | --- | --- | --- |
| **Low** | `intervalMs <= 300,000` (`1m`, `5m`) | `pivotSpan: 4` on `sr`, `trend`, `channel`, `structure`, `liquidity`, `divergence` | `3` |
| **Low** | `intervalMs <= 300,000` (`1m`, `5m`) | `fvg.minGapAtr: 0.45` | `0.3` |
| **Low** | `intervalMs <= 300,000` (`1m`, `5m`) | `zones.impulseAtr: 2.5` | `2.0` |
| **Baseline** | `15m`, `1h`, `4h` | None | Base defaults |
| **High** | `intervalMs >= 86,400,000` (`1d`) | `pivotSpan: 2` on `sr`, `trend`, `channel`, `structure`, `liquidity`, `divergence` | `3` |
| **High** | `intervalMs >= 86,400,000` (`1d`) | `range.minBars: 8` | `12` |

Why these shifts matter:
- On `1m`/`5m` charts, tighter `pivotSpan: 4` filters micro-wick noise, while higher `fvg.minGapAtr` and `zones.impulseAtr` reject tiny spread gaps and weak 1-minute candles.
- On `1d` charts, `pivotSpan: 2` catches macro swings without requiring 7-day clusters, and `range.minBars: 8` detects 1–2 week consolidations promptly.

## Automatic `VWAP` Session Anchoring

The rolling `VWAP` indicator inspects candle spacing (`dt = t[1] - t[0]`) via `inferVwapAnchor()`:

- **`<= 1h` (`1m`, `5m`, `15m`, `1h`)**: Resets daily at `00:00 UTC` (`Math.floor(ms / 86_400_000)`).
- **`4h`**: Resets weekly at **Monday `00:00 UTC`** (`Math.floor((ms + 3 * 86_400_000) / (7 * 86_400_000))`).
- **`1d`**: Resets monthly on the **1st at `00:00 UTC`** (`year * 12 + month`).

On higher timeframes, resetting VWAP every 24 hours would collapse to a single candle's typical price (`H+L+C)/3` with zero variance. Stepping automatically to Weekly on `4h` and Monthly on `1d` keeps standard-deviation bands meaningful across every timeframe.

## Uniform Multi-Timeframe (HTF) Pipeline

Three studies consume higher-timeframe context (`HTF_STUDIES`): [`sessions`](https://docs.kami.trade/studies/sessions/), [`htf`](https://docs.kami.trade/studies/htf/), and [`auto`](https://docs.kami.trade/studies/auto/). Rather than adding custom per-venue endpoints, Kami uses a uniform hybrid pipeline across every venue:

1. **Lazy demand**: HTF candles are only fetched when an HTF study is active on the chart or requested by Kami AI.
2. **Local coverage check first**: Before hitting the network, `countCompleteBuckets()` checks in `O(n)` zero-allocation time whether the active chart already spans at least `60` complete HTF buckets.
3. **Background fetch & cache**: If local coverage is short, `requestHtf()` fires a non-interrupting background load through the standard chart loader (reusing IndexedDB cache and throttling duplicate requests up to `min(intervalMs, 5 min)`). Results live in a `16`-entry LRU cache (`market.getHtf`).
4. **Automatic boundary rollover**: Once a cached HTF bucket rolls over (`now - 5s` crosses the next HTF bar boundary, with a 5-second settlement grace period), Kami refreshes the HTF series automatically.
5. **Local aggregation fallback**: While background HTF history is loading (or offline), `aggregateSeries()` builds complete HTF OHLCV buckets directly from the active chart's closed candles, dropping any incomplete trailing bucket.
6. **Zero-lookahead clamp**: `closedHtf()` trims any HTF bar whose close timestamp exceeds `Math.min(input.now, windowEnd)`. When you pan backward in `View` scope, `htf` and `sessions` strictly reflect what was knowable at the right edge of your historical window.
