# Higher Timeframe (HTF)

> Projects higher-timeframe support/resistance bands, unfilled Fair Value Gaps, and dealing-range equilibrium onto the active chart.

Canonical page: [https://docs.kami.trade/studies/htf/](https://docs.kami.trade/studies/htf/)

`htf` computes support/resistance, Fair Value Gaps, and market-structure trend on higher timeframes and projects every in-bounds level cleanly onto your execution chart with zero lookahead.

## Parameters

| Parameter | Default | Range | Type | Timeframe overrides |
| --- | --- | --- | --- | --- |
| `window` | `500` | `60..2000` | integer | — |
| `maxLevels` | `3` | `1..6` | integer (per HTF) | — |
| `maxFvg` | `2` | `0..4` | integer (per HTF) | — |

## Timeframe Mapping (`HTF_MAP`)

| Active chart | Projected higher timeframes |
| --- | --- |
| `1m`, `5m` | `1h`, `1d` |
| `15m`, `1h` | `4h`, `1d` |
| `4h` | `1d` |
| `1d` | None (emits empty result) |

## Algorithm & Nuances

1. **Zero-lookahead HTF input**: Uses supplied closed HTF candles trimmed to `Math.min(input.now, windowEnd)` so panning back in history never reveals future HTF bars. If a target HTF is not yet cached, aggregates complete buckets locally from the active chart's `Series`. Requires at least `30` closed HTF bars per target timeframe (`<= 500` bars kept).
2. **HTF sub-analysis**: Runs `sr` (up to `maxLevels`, keeping non-broken levels), `fvg` (up to `maxFvg`), and `structure` (`maxLabels: 0, maxEvents: 1`) using parameters resolved for the higher timeframe (`resolveParams(..., tfMs)`).
3. **Cross-timeframe alignment**: Classifies `facts.alignment` across all analyzed HTFs as `'aligned_bull'` (all bullish), `'aligned_bear'` (all bearish), `'mixed'` (disagreeing trends), or `'none'`.
4. **In-bounds projection & graceful band→level fallbacks**:
   - All projected drawings are checked against the execution chart's visible price envelope `[ltfLo - boundAtr, ltfHi + boundAtr]`.
   - **HTF S/R**: Emits a full `band` (with `+20` edge-label priority boost over LTF bands) when `[bLo, bHi]` fits cleanly inside `[minP, maxP]`. If an HTF band's edge spills outside the LTF range while its center `price` is in bounds, it falls back cleanly to a `level` line (`${tfTag} S|R`).
   - **HTF FVG**: Clamps `from` to the LTF timeline via `lowerBound`. Emits a faint `zone` when `[g.low, g.high]` fits inside the spanned LTF price bounds; otherwise falls back to a `level` at Consequent Encroachment (`${tfTag} FVG CE`).
   - **HTF Dealing Range `EQ`**: Emits a neutral `level` (`${tfTag} EQ (premium|discount|equilibrium)`) when in bounds.

## Drawings & Facts

- **Drawings**: Tagged with uppercase timeframe prefixes (`1H`, `4H`, `1D`) across `band`/`level` S/R, faint `zone`/`level` FVGs, and `level` EQ lines.
- **Facts (`HtfFacts`)**: `lastClose`, `alignment`, and `timeframes[]` (`interval`, `trend`, `levels`, `gaps`, `dealingRange`).

## Activation

- **Studies menu**: `Higher timeframe: HTF S/R, FVGs and EQ` (`HTF`)
- **Slash command**: `/htf`
- **Chat phrases**: `htf`, `mtf`, `higher timeframe`, `multi timeframe`, `htf levels`
