# Overlay Indicators

> Exact formulas, default periods, and nuances for Kami's five price-pane overlays — MA, EMA, BOLL, VWAP, and SUPERTREND.

Canonical page: [https://docs.kami.trade/indicators/overlays/](https://docs.kami.trade/indicators/overlays/)

Overlay indicators plot directly on the main candlestick pane alongside active studies.

## `MA` (Simple Moving Average)

- **Defaults**: `calcParams: [5, 10, 30, 60]` on candle closes (`c`).
- **Formula**: Neumaier-compensated rolling sum divided by `period`. First valid value at bar `period - 1`.
- **Nuance**: Compensated addition eliminates cumulative floating-point drift when removing stale values from long streams.

## `EMA` (Exponential Moving Average)

- **Defaults**: `calcParams: [6, 12, 20]` on candle closes (`c`).
- **Formula**: Smoothing factor `k = 2 / (period + 1)`, seeded with the arithmetic mean (SMA) of the first `period` closes (matching TA-Lib `EMA`), then `prev = (x[i] - prev) * k + prev`.
- **Nuance**: Because seeding uses an exact `period`-bar SMA rather than `x[0]`, early values stay aligned with institutional charting packages and TA-Lib.

## `BOLL` (Bollinger Bands)

- **Defaults**: `calcParams: [20, 2]` (`period = 20`, `mult = 2`).
- **Outputs**: `UP`, `MID`, `DN` (`bandwidth` and `%b` are also computed in the reference kernel `bbands()`).
- **Formula**:
  - `MID = SMA(close, 20)`
  - `σ = population standard deviation` (`ddof = 0`), computed via a **two-pass** variance loop over each `period` window around `MID` (avoiding catastrophic cancellation from one-pass `E[x²] - E[x]²`).
  - `UP = MID + mult * σ`, `DN = MID - mult * σ`.

## `VWAP` (Session Volume-Weighted Average Price)

- **Defaults**: `calcParams: [1, 2]` (`±1σ` and `±2σ` dashed bands around solid accent `VWAP`).
- **Timeframe-aware UTC reset (`inferVwapAnchor`)**:

| Chart interval | Reset cadence | Bucket key |
| --- | --- | --- |
| `1m`, `5m`, `15m`, `1h` | Daily `00:00 UTC` | `floor(ms / 86_400_000)` |
| `4h` | Weekly Monday `00:00 UTC` | `floor((ms + 3 * 86_400_000) / (7 * 86_400_000))` |
| `1d` | Monthly 1st `00:00 UTC` | `UTCYear * 12 + UTCMonth` |

- **Formula**: Accumulates typical price `tp = (h + l + c) / 3` weighted by positive volume `v > 0` using **West-Welford weighted online variance** (`sd = sqrt(m2 / wSum)`). Zero-volume bars carry forward the running mean and variance without corrupting weights (emitting `NaN` only if cumulative session volume is still `0`).
- **Incremental parity**: The resumable kernel (`incremental.ts`) checkpoints `[curBucket, wSum, mean, m2]` before the forming bar and executes the exact same floating-point operations as batch `vwap()`, matching bit-for-bit (`Object.is`).

## `SUPERTREND`

- **Defaults**: `calcParams: [10, 3]` (`period = 10`, `mult = 3`), short label `ST`.
- **Outputs**: `UP` (green trailing support stop while bullish; `NaN` when bearish) and `DN` (red trailing resistance stop while bearish; `NaN` when bullish).
- **Formula**:
  - Computes Wilder-smoothed `ATR(period)` starting from `mean(TR[1..period])` at bar `period`.
  - Raw bands around midpoint `hl2 = (h + l) / 2`: `rawUp = hl2 - mult * atr`, `rawDn = hl2 + mult * atr`.
  - Trailing ratchet:
    - `fUp = (rawUp > prevUp || c[i - 1] < prevUp) ? rawUp : prevUp`
    - `fDn = (rawDn < prevDn || c[i - 1] > prevDn) ? rawDn : prevDn`
  - Direction flips only on a confirmed close beyond the active trailing stop (`c[i] < fUp` flips bearish; `c[i] > fDn` flips bullish).
