# Support & Resistance

> Multi-scale fractal swing clustering with recency, volume, and wick weighting plus flip/break tracking.

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

`sr` identifies horizontal support and resistance bands by clustering confirmed fractal swings around high-density price zones, weighted by recency, volume, wick rejection, and higher-scale swing confluence.

## Parameters

| Parameter | Default | Range | Type | Timeframe overrides |
| --- | --- | --- | --- | --- |
| `window` | `500` | `60..2000` | integer | — |
| `pivotSpan` | `3` | `2..10` | integer | `4` on `<= 5m`, `2` on `>= 1d` |
| `tolAtr` | `0.35` | `0.05..2` | number | — |
| `minTouches` | `2` | `2..10` | integer | — |
| `max` | `5` | `1..12` | integer | — |
| `halfLife` | `0.33` | `0.05..2` | number | — |

## Algorithm & Nuances

1. **Multi-scale fractal pivots**: Runs `fractalPivots` at `pivotSpan` and marks swings that also qualify at `majorSpan = min(10, pivotSpan * 2)` (`majorMask`).
2. **Per-touch weighting**: Each swing touch receives weight `recency * vol * wickMult * majorMult`:
   - `recency = halfWeight(n - 1 - at, halfLife * n)` (exponential decay with half-life equal to `halfLife` fraction of the window).
   - `vol = clamp(sqrt(v[at] / medVol), 0.5, 2)` (`1` when `medVol <= 0`).
   - `wickMult = 0.85 + 0.5 * wickFrac` (upper wick ratio on swing highs, lower wick ratio on swing lows).
   - `majorMult = 1.6` if the swing is also a major pivot, else `1.0`.
3. **Density-peak greedy clustering**: Sorts swings by price and repeatedly selects the unconsumed window `[start, start + 2 * tol]` (`tol = atr[n - 1] * tolAtr`) with at least `minTouches` swings and maximum total weight. Consumes its members and computes the weighted mean price `L`.
4. **Dynamic-ATR crossings & role flip**: Walks forward from the first touch to `n - 1` using per-bar tolerance `atr[k] * tolAtr`. Counts close switches across `[L - barTol, L + barTol]`.
   - `role = lastClose >= L ? 'support' : 'resistance'`.
   - `status = 'holding'` when `crossings === 0`; `'flipped'` when a touch after `lastCross` retests from the new side; `'broken'` otherwise.
5. **Scoring & strength**:
   - `score = r2(weight / (1 + 0.5 * crossings) / (1 + distAtr / 8))`.
   - `strength = 'strong'` if unbroken and (`majorTouches >= 2` or `touches >= 4 && score >= 2`); `'moderate'` if unbroken and (`majorTouches >= 1` or `touches >= 3`); else `'weak'`.
6. **Selection guarantee**: Reserves slots for the highest-scoring non-broken support and non-broken resistance first, fills remaining slots up to `max` by descending `score`, and outputs sorted descending by price.

## Drawings & Facts

- **Drawings**: Up to `max` `band` overlays spanning `[L - tol, L + tol]` with center line `L`. Broken levels render `'faint'` in `'neutral'` tone with their original role label (`Broken S` / `Broken R`); holding and flipped levels render `'up'` (support) or `'down'` (resistance).
- **Facts (`SrFacts`)**: `atr`, `lastClose`, and `levels[]` containing `price`, `role`, `status`, `touches`, `majorTouches`, `touchTimes`, `lastTouchTime`, `crossings`, `band`, `distanceAtr`, `strength`, and `score`.

## Activation

- **Studies menu**: `Support and resistance` (`S/R`)
- **Slash command**: `/sr`
- **Chat phrases**: `support`, `resistance`, `s/r`, `levels`, `horizontals`
