OPEN-SOURCE SCRIPT

Sweep and Cluster [JOAT]

1 067
SWEEP AND CLUSTER [JOAT]

A two-stage liquidity-sweep engine. Most public "sweep" indicators print a label on every wick that pokes past a recent high or low — which is mostly noise. Sweep and Cluster requires two separate events to register a tradeable signal: first a strict 5-condition sweep, then a confirming cluster of price action in the rejection direction. The label that actually appears on the chart is the rare intersection — the moments where institutional stop-running is followed by genuine commitment in the opposite direction.

Snapshot

Stage 1 — Strict 5-condition sweep detection

A sweep is registered only when all of these are true on the same bar:

  • Real pivot reference — the swept level is an actual minor pivot (ta.pivothigh / ta.pivotlow) from the rolling cache, not a rolling max/min. A scan-depth input controls how far back to look; a minimum-age gate prevents self-reference.
  • Wick magnitude — the wick that exceeds the pivot must be at least Wick ATR Multiplier × ATR(14) (default 0.8 ATR). The KB-published strict threshold.
  • Wick dominance — wick length must be at least Wick/Range Ratio of the candle's total range (default 35%). The wick must dominate the bar's shape, not be a side-effect of a large body.
  • Closing direction — close must be back inside the swept level. A clean wick that closed beyond the pivot is a breakout, not a sweep — and is filtered out by construction.
  • Cooldown — at least N bars (default 8) since the last same-side sweep. Prevents one stop-run from being counted as multiple sweeps when the wick prints over several bars.


If all five conditions are met a pending marker is placed (optional). Pending markers represent "a sweep happened" but not yet "the sweep was meaningful" — until the cluster confirms, the sweep is not actionable.

Stage 2 — Cluster confirmation

After a sweep fires, the next N bars (cluster window, default 5) are monitored for confirming follow-through. The cluster confirms only when:

  • At least M bars (default 1) close against the swept direction inside the window.
  • Average body/range across the qualifying cluster bars exceeds the Min Body Ratio (default 0.25) — the rejection candles must be impulsive, not micro-bodies.
  • Cumulative volume across the cluster window is at least Volume Multiplier × Average Volume (default 0.8×). Without volume the cluster is not commitment.


When all three confirm, the script fires the SAC (Sweep And Cluster) label — the actionable signal. A cluster strength badge (body sum / ATR) is rendered next to the label so you can rank one SAC vs another at a glance.

A failed sweep marker (toggleable, off by default) tracks sweeps that expired without confirming — useful for auditing the false-positive rate visually and for choosing thresholds.

Visual system

  • Sweep wick highlight — a thin coloured line at the swept reference price, extended right by a configurable number of bars. Makes the rejection unmistakable.
  • Reference level triangle — small glyph at the actual pivot level that was swept.
  • Cluster candle override — when SAC fires, the confirming cluster candles are repainted in the active-side theme colour via plotcandle so the move stands out from background.
  • Optional background tint — fading directional bgcolor for a few bars after a confirmed SAC.
  • Optional bar paint by active bias — every bar painted bull/bear based on the most recent SAC. Off by default to preserve chart neutrality.


A locked Quantum palette (cyan-quantum bull / pink-quantum bear on a deep void) gives the chart a distinctive sweep-and-reverse identity.

Snapshot

Dashboard + rolling statistics

A monospaced table, positionable to any of nine corners, with vertical row-fade for premium feel. Surfaces:

  • Total sweeps and total SACs since the last session/day/week reset (configurable reset frame).
  • Rolling Confirmation Rate (% of recent sweeps that became SACs) over a configurable window (default 50). The script's own success metric.
  • Pending sweep status with bars-remaining-in-cluster-window.
  • Last SAC direction with strength badge and bars-ago.
  • Last failed sweep tag (when failed markers are enabled).


Confirmation Rate is the headline read — it lets you see whether the current threshold settings are producing meaningful or sparse signals on the instrument you are trading.

Alerts

Three alert conditions, each independently controllable:

  • Pending Sweep (Stage 1 fires)
  • SAC Confirmed (Stage 2 confirms)
  • SAC Failed (Stage 2 expires without confirming) — off by default


How to read it

Two reads, in order of conviction:

  1. SAC Confirmed alert with a high strength badge — the script's intended signal. Liquidity was swept, a real rejection followed inside the window, and the rejection had body and volume. This is the actionable read.
  2. Pending Sweep at a known structural level (S/R, supply/demand) — useful as a "watch for the cluster" warning. If the cluster confirms, you have a high-conviction reversal at a structural location.


In persistent trends the failed-sweep rate climbs — that is the script telling you the regime does not currently favour sweep-and-reverse setups; stand aside or use the script in the trend direction only.

Suggested settings

Defaults (pivot lookback 8, wick ATR 0.8, body ratio 0.35, cluster window 5) are tuned for 15m–1H on liquid markets. For scalping (1m–5m), drop pivot lookback to 4 and cluster window to 3. For HTF macro reads (4H+), raise pivot lookback to 12–20 and cluster window to 8. The strict-threshold wick filters (0.8 ATR + 35%) are intentionally institutional — loosen for less liquid instruments.

Originality

The implementation — the five-condition strict sweep gate, the rolling minor-pivot cache with age and scan-depth filters, the three-condition cluster confirmation, the cluster-strength badge calculation, the pending → confirmed → failed state machine, the wick-level highlight render, the plotcandle override for confirming bars, the rolling confirmation-rate metric, and the session-reset counter — is JOAT-original. No third-party code reused. The "sweep + reaction" pattern is well-known to professional tape readers; the strict double-gate implementation is built specifically for chart-based Pine data.

Limitations

A confirmed SAC requires the cluster window to elapse — by definition the signal carries the cluster window bars of lag relative to the sweep. This is intentional; the cluster is what makes the signal meaningful. Failed sweeps are expected — the confirmation rate metric is there for you to see and tune accordingly. The script is structure-aware (uses real pivots) but does not know about HTF structure; combine with a higher-timeframe S/R indicator for best fit.





-made with passion by jackofalltrades

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.