# Liquidity Pools

> Resting equal highs (BSL) and equal lows (SSL) clustering paired with causal Swing Failure Pattern (SFP) sweep detection.

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

`liquidity` locates resting stop-loss clusters at Equal Highs (`EQH` / Buy-Side Liquidity) and Equal Lows (`EQL` / Sell-Side Liquidity), and marks causal Swing Failure Pattern (`SFP`) wick sweeps that close back inside.

## 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.25` | `0.05..1.5` | number | — |
| `maxPools` | `4` | `1..8` | integer | — |
| `maxSweeps` | `4` | `0..8` | integer | — |

## Algorithm & Nuances

1. **Equal Highs (`BSL`) & Equal Lows (`SSL`)**:
   - Greedily clusters fractal swing highs (and separately swing lows) within `tol = tolAtr * atr[n - 1]` of the running cluster mean.
   - Requires at least `2` touches separated by at least `5` bars (`lastIdx - firstIdx >= 5`).
   - Pool price snaps to the outer extreme (`max(h)` for `BSL`, `min(l)` for `SSL`).
   - Drops broken pools where any candle after `firstIdx` closed beyond `level`. Flags `swept = true` if a later bar wicks `> 0.05 * atr[k]` past `level` and closes back inside.
   - Scores by `r2((touches * (1 + min((lastIdx - firstIdx) / n, 0.75))) / (1 + distAtr / 4))`, balancing `ceil(maxPools / 2)` `BSL` and `ceil(maxPools / 2)` `SSL` pools.
2. **Causal `SFP` Stop-Hunt Sweeps**:
   - For every confirmed swing at index `j`, scans forward starting at `k = j + pivotSpan + 1` (strictly after right-side pivot confirmation).
   - Stops scanning a swing if a candle closes past it. Logs a sweep on the first bar wicking `> 0.05 * atr[k]` beyond the swing and closing back inside.
   - Records `sweepDepthAtr`, relative volume `volRatio`, `source` (`'eq_pool'` vs `'swing'`), and `followThrough` (whether any of the next `1–3` closes moved in the reversal direction).
   - Deduplicates per `(side, bar)` favoring `eq_pool` over single swings, then deeper sweeps; keeps the most recent `maxSweeps`.

## Drawings & Facts

- **Drawings**:
  - Up to `maxPools` dashed extended `trendline` rays labeled `EQH ×N` (`'down'`) or `EQL ×N` (`'up'`).
  - Up to `maxSweeps` `mark` labels (`Sweep ↓` above / `'down'`, `Sweep ↑` below / `'up'`).
- **Facts (`LiquidityFacts`)**: `lastClose`, `pools[]`, and `sweeps[]`.

## Activation

- **Studies menu**: `Liquidity: equal highs, lows and sweeps` (`Liq`)
- **Slash command**: `/liquidity`
- **Chat phrases**: `liquidity`, `liq`, `eqh`, `eql`, `sweep`, `sfp`, `stops`, `bsl`, `ssl`, `equal highs`, `equal lows`
