OPEN-SOURCE SCRIPT
Zaktualizowano

Liquidity Sweep Mean Reversion [XAUUSD/XAGUSD]

1 985
# Liquidity Sweep Mean Reversion [XAUUSD/XAGUSD]
### Professional Institutional Orderflow Strategy for Gold & Silver — M1 to M15

---

## Overview

This strategy is built around one of the most reliable and repeatable patterns in intraday precious metals trading: **liquidity sweeps followed by mean reversion**. Large institutional participants systematically drive price into clusters of stop orders resting above swing highs or below swing lows — triggering retail stops before reversing sharply in the opposite direction. This script detects those engineered moves in real time and positions entries precisely at the point of reversal.

Optimized for **XAUUSD and XAGUSD** on timeframes from **M1 through M15**, the strategy combines institutional orderflow concepts with technically sound confirmation filters to produce high-quality, well-defined trade setups.

---

## How It Works

### 1. Liquidity Zone Detection
The script continuously maps the highest high and lowest low of the last **20 and 50 bars** (both lookback periods are fully adjustable). These zones represent areas where stop orders from retail traders accumulate — the primary targets for institutional order flow.

### 2. Sweep Detection
A sweep is confirmed when a candle's wick **breaks through a liquidity zone** but the candle **closes back inside the range** — the classic stop-hunt / fakeout pattern. This single condition identifies the moment liquidity has been collected and a reversal is likely.

### 3. Entry Confirmation
Raw sweep signals are filtered through two additional layers before an entry is triggered:
- **EMA Cross** (configurable Fast/Slow EMA, default 9/13): Price must reclaim the EMA after the sweep
- **VWAP Filter**: Long setups require price above VWAP; Short setups require price below VWAP

---

## Strategy Modes — Adjustable Aggression

Three distinct entry modes give full control over the risk/reward profile:

| Mode | Entry Trigger | Best For |
|---|---|---|
| **Conservative** | Market Structure Shift (break of last swing high/low after sweep) + EMA + VWAP | Lower frequency, highest confirmation |
| **Balanced** | Candle close back inside range + EMA cross + VWAP | Default — best overall balance |
| **Aggressive** | Immediate entry at the sweep candle | Highest frequency, tightest SL, requires active management |

---

## Precision Exit Management

- **Stop Loss** — Placed just beyond the wick of the sweep candle (with configurable % buffer), making the SL technically invalidating for the setup
- **Take Profit** — Automatically targets the opposing liquidity pool (next significant high/low)
- **Minimum RRR Filter** — Trades are only executed when the calculated Risk/Reward Ratio meets or exceeds the configured minimum (default 1:1.5). Substandard setups are skipped entirely
- **Partial Close** — Optionally closes 50% of the position at EMA touch (configurable %), locking in profit while letting the remainder run to full TP

---

## Visual Tools

- **Liquidity Zone Boxes** — Subtle gray boxes marking both lookback zones on the chart
- **Sweep Markers** — Small ✕ symbols placed directly on confirmed sweep candles
- **BUY / SELL Labels** — Signal labels showing entry direction and live RRR value
- **MSS Markers** — Triangles marking confirmed Market Structure Shifts (Conservative mode)
- **SL / TP Lines** — Dashed lines showing exact Stop Loss and Take Profit levels for the active position
- **Session Shading** — Out-of-session bars are visually dimmed

---

## Live Dashboard (Top Right)

A compact, always-visible panel displays:

| Field | Description |
|---|---|
| Mode | Active strategy mode |
| VWAP Status | Current Bullish / Bearish bias relative to VWAP |
| Daily Vol (K) | Intraday cumulative volume in thousands |
| ATR(14) | Current volatility reading |
| Sweep | Active sweep signal status |
| Position | Current open trade direction |
| RRR | Risk/Reward Ratio of the last signal |
| Session | Time filter status (Active / Inactive) |

---

## Alert Conditions (Webhook Ready)

Six fully configurable alert conditions for push notifications and webhook integrations:

- 🟢 **LONG Signal** — Full entry signal confirmed
- 🔴 **SHORT Signal** — Full entry signal confirmed
- ⚡ **Bullish Sweep** — Raw sweep detected (bearish to bullish)
- ⚡ **Bearish Sweep** — Raw sweep detected (bullish to bearish)
- 🔵 **MSS Bullish** — Market Structure Shift to the upside
- 🔵 **MSS Bearish** — Market Structure Shift to the downside

---

## Time Filter

Built-in session filter (default **08:00 – 20:00 UTC**) excludes low-liquidity dead-market periods. Both start and end times are fully configurable. Active during London and New York sessions by default.

---

## Key Settings at a Glance

| Parameter | Default | Description |
|---|---|---|
| Strategy Mode | Balanced | Entry aggression level |
| Lookback Short | 20 | Bars for short-term liquidity zones |
| Lookback Long | 50 | Bars for long-term liquidity zones |
| EMA Fast | 9 | Fast EMA for cross confirmation |
| EMA Slow | 13 | Slow EMA for cross confirmation |
| VWAP Anchor | Session | VWAP reset period |
| Min RRR | 1.5 | Minimum acceptable Risk/Reward |
| SL Buffer | 0.5% | Percentage offset beyond sweep wick |
| Partial TP | On | Close 50% at EMA touch |
| Time Filter | 08:00–20:00 UTC | Active trading session window |

---

## Recommended Setup for XAUUSD M5

- **Mode:** Balanced
- **Lookback:** 20 / 50
- **SL Buffer:** 0.3–0.5%
- **Min RRR:** 1.5
- **Session:** 08:00–20:00 UTC (London + New York)

---

*This script is intended as a decision-support tool. Past performance in backtesting does not guarantee future results. Always apply proper risk management.*
Informacje o Wersji
Some bugfixes that caused freezing the code. New Alerts added
Informacje o Wersji
UI translation fix
Informacje o Wersji
VWAP filtered Sweeps are now chooseable, Trendfilter MA´s changed. Dashboard is now adjustable.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.