XAU sweepScalper
- 专家
- 版本: 9.50
- 激活: 5
# XAU Sweep Scalper v9.5 (MetaTrader 5)
An Expert Advisor for XAUUSD built on market structure, liquidity and supply/demand. It trades any session, has no indicator filters (no RSI, no EMA) and no news filter. Every setup is placed as pending orders, and trades are scaled in with multiple entries.
## How it trades
**Bias.** The M15 market structure (higher highs/lows vs lower lows/highs, a trend flip needs a candle body close beyond the last swing) gives the direction. With `InpUseHTFStructure` on, the H1 must agree, so the EA trades only when the H1 pullback is over. There are no trades while the M15 is consolidating (no break of structure for 8 hours). A break of equal highs/lows against the trend counts as a liquidity sweep, not a trend change.
**Three setups, all pending orders.** Only supply/demand, liquidity sweeps and false breakouts. The order comment names the setups behind it, for example `XAU FalseBreak+Sweep 1/5`.
| Setup | When | Order |
|---|---|---|
| Zone | Price is within $3 of an untested M15 supply/demand zone that has liquidity (it swept liquidity when it formed, or inducement sits in front of it, already taken). | Limit at the zone edge. SL beyond the zone. |
| FalseBreak | Within the last hour, price ran a strong, equal, M15 swing or recent low (wick or close below, up to $8), got back above it, and a 1m candle **body closed above the last high of the leg into that low** (break of structure). Sells are the mirror. | Limit at the refined zone: the last bearish candle before the move that broke structure (still untested). SL below the false-break low. |
| Sweep | A wick runs a strong, equal, M15 swing or recent level and the 1m closes back inside, with no candle closing beyond it. Skipped if the sweep stopped inside an open imbalance. | Stop order just beyond the rejection candle. SL beyond the sweep. |
**Entries.**
- Each setup opens with **2 pending orders** at the same price (`InpBaseEntries`).
- When **2 or more setups are valid at the same time in the same direction**, it opens with **5** instead (`InpAlignedEntries`, `InpAlignMin`). The highest-priority setup (Zone, then FalseBreak, then Sweep) sets the price and stop.
- If price moves against the trade **50% of the way from entry to SL**, it adds **2 market orders** with the same SL and TP (`InpAddEntries`, `InpAddAtPct`). This happens once per trade. If the market is closed at that moment (daily break or weekly open), it retries on the next tick instead of giving up.
**Controlled hedge** (`InpHedge`, on by default, hedging accounts only):
- If price gets **75% of the way from entry to SL** (`InpHedgeAtPct`), after the drawdown adds, it opens **one** opposite market order, sized at **half** the trade's open volume (minimum 0.01). Only one hedge per trade.
- The hedge's SL is the trade's entry price. If price comes back, the trade recovers and the hedge closes with a small loss.
- Its TP is 1R beyond the trade's SL. If the trade gets stopped out, the hedge keeps running and its SL moves to breakeven as soon as it's in profit, so what's left can't lose.
- What it does to the numbers: if the trade is stopped out, the hedge has already earned back about 0.125R of the trade's volume, plus anything it makes past the SL. If price returns to entry, the hedge costs about 0.375R of the trade's volume. It never adds risk on the trade's side.
- On a netting account an opposite order would just shrink the trade, so the hedge is skipped and the log says so.
**Lot size** (`InpLotMode`):
- **Fixed lot per entry (default):** every entry, including the drawdown adds, uses `InpFixedLot` (0.01). A full trade is up to 4 × 0.01 (or 7 × 0.01 when setups align), so check what that means against the stop distance for your account.
- **Risk % for the whole trade:** `InpRiskPercent` (1%) covers all entries including the adds. Each entry gets that risk divided by all planned entries (2 + 2 = 4, or 5 + 2 = 7) at the initial stop distance. The adds sit closer to the stop, so the real combined risk ends up below the setting. If the per-entry size falls below your broker's minimum lot, the trade is skipped and the log says so.
**Small accounts ($10).** When the lot size comes out below the broker minimum, the EA uses the minimum lot (0.01) and drops entries instead of skipping: first the drawdown adds, then pending entries, down to a single entry. It keeps going down until the whole trade at its stop loses no more than half the balance and fits the free margin. If even one 0.01 entry doesn't fit, the trade is skipped and the log says why. On a $10 account, that means one 0.01 entry with a stop of $5 or less, and enough leverage for the margin (about 1:500 or higher).
**Exits.** The TP is the next liquidity target (untaken swing, strong or equal high/low, opposing zone, the far side of an open imbalance, or the H1 swing), capped at `InpRewardR` (3R). A setup is skipped if that target is closer than 1.5R. At 1R (`InpBEAtR`) every position in the trade moves its stop to breakeven at the first entry's price.
**One trade at a time.** While orders are pending or positions are open, no new setups are placed. Unfilled orders are cancelled after 4 hours, when the bias flips, or when price reaches their stop. Leftover pending orders are deleted when the trade closes.
**Market hours.** The EA only sends orders, cancels or modifications while the symbol is inside its trading session (it skips the daily break, weekends and holidays, plus a minute at each edge). If the broker still answers "market closed", it waits a minute before trying again.
**Other symbols.** All distances are written in gold dollars. On any other symbol they're scaled by price ÷ 3000 (EURUSD 0.80 ≈ 3 pips), so the EA can still trade there. That's mainly for the MQL5 Market validator; the strategy is built for XAUUSD.
**Broker checks (MQL5 Market rules).** Before every order the EA checks the volume (step, minimum, maximum and the symbol's total volume limit), the free margin, the stops/freeze level for SL and TP (measured from Bid for buys and Ask for sells, and from the spread when the broker uses a floating stops level), the margin for each pending order, and the account's pending-order limit. It never modifies with unchanged values, and never deletes an order inside the freeze level. An order that doesn't fit is made smaller or skipped, and the log says why. It is never sent and rejected.
## Inputs (24)
| Group | Inputs |
|---|---|
| Lot size | Mode (fixed lot / risk %), fixed lot, risk % per trade |
| Risk | Max R, SL buffer, max SL distance, breakeven R |
| Entries | Base entries, aligned entries, setups needed to align, drawdown adds, add trigger % |
| Hedge | On/off, trigger % |
| Setups | Zone, FalseBreak, Sweep on/off |
| Structure | HTF, MTF, HTF must agree |
| General | Pending expiry, max spread, magic number, slippage |
Everything else (swing size, zone detection, equal-level tolerance, false-breakout window, arm distances) is fixed as constants at the top of the file. They can be edited there if a backtest calls for it.
## What is an approximation
- Swings are fractals (3 bars each side). A zone is the base candle before an impulsive candle that left an imbalance. Imbalances are expected to fill completely, so entries are at the zone, never inside the gap.
- "Aligned" means the setups were valid on the same 1m bar in the same direction. They can point at slightly different prices; the highest-priority one is used.
- A false breakout is confirmed on the 1m: the break of structure is a body close beyond the highest high (lowest low) of the 15 bars before the false-break extreme.
## Install
1. In MT5: **File → Open Data Folder → MQL5 → Experts**, copy `XAU_SweepScalper.mq5` there.
2. Open it in MetaEditor and press **Compile** (F7). It was written without access to MetaEditor, so if the compiler reports anything, paste the error back in the thread.
3. Attach it to an XAUUSD chart and enable **Algo Trading**. The chart comment shows the bias, H1/M15 trend, strong and equal levels and zone counts.
## Backtest before live
- Strategy Tester, **Every tick based on real ticks**, with your broker's real spread and commission.
- With no session or news filter, it will also trade the Asian session and through high-impact news. Watch how those trades do in the backtest.
- Adding in drawdown improves the average entry but makes losing trades use the full risk more often. Compare `InpAddEntries` = 2 vs 0.
- Test each setup on its own, then all together, then run on demo for a few weeks before real money.
