# N30 Gold Reversion – TickRobust (MT5)

- **Upstream:** https://github.com/n30dyn4m1c/gold-pro-scalper, file `XAU_Quant_Reversion_TickRobust.mq5` (commit `7794c91`)
- **Author / licence:** Neo Malesa, MIT
- **Platform:** MetaTrader 5 (`.mq5`)
- **Market:** XAUUSD / GOLD only. Set `InpTradeSymbol` to your broker's exact name (e.g. `XAUUSD`, `GOLD`, `XAUUSD.m`).
- **Timeframe:** M1, with an optional H1 trend filter

Only the TickRobust variant is included. The other files in the upstream repo keep the 10%-per-trade risk tiers and are less robust under real-tick testing (per their own README).

## Strategy: mean reversion on M1

Decisions are made once per bar on closed-bar data. A trade needs all of:

1. **Stretch:** close is more than 2.2 standard deviations from SMA20 (Z-score).
2. **Turn:** the last closed bar stopped extending the stretch (no catching a falling knife).
3. **Range regime:** ADX(14) ≤ 22. It stands aside in trends.
4. **Volatility regime:** ATR between 0.4× and 2.0× its 50-bar average.
5. **Cost gate:** StdDev ≥ 3× and distance to the mean ≥ 4× the round-trip cost (spread + `InpExtraCostPts`).
6. **Filters:** spread ≤ 50 points, 10:00–20:00 broker time, no red-folder USD news (MQL5 calendar), 15 min cooldown after a loss, optional H1 SMA50 alignment.

**Exits:** take-profit at the mean (retargeted each bar), Z back inside ±0.2, a 40-bar time limit, break-even after 1× ATR, and a server-side SL of max(800 points, 2.5 × ATR). Friday close at 20:00.

## Risk controls (verified in code)

| Control | Default in this copy |
|---|---|
| Risk per trade | **0.5%** (upstream 2%) |
| Dynamic risk tiers | **Off** (upstream on: 10% per trade below $500) |
| Daily loss cap | **2%** (upstream 15%) |
| Max positions | 1 |
| Loss cooldown | 15 min |
| News | Block 60 min before / 120 min after; close before news |

No martingale, grid, averaging, or lot increase after a loss.

## Patches in this copy

- `NormalizeLot` no longer rounds up to the broker minimum, so the existing "lot below minimum → skip" check in the trade function now works.
- `InpUseDynamicRisk=false`, `InpRiskPct=0.5`, `InpMaxDailyLossPct=2.0`.

## $50 account: not suitable on a standard contract

On a 100 oz contract, 0.01 lot = 1 oz, so the minimum 800-point ($8.00) stop loses about **$8, or 16% of $50**. At 0.5% risk the EA will skip every trade, by design. Only use it on a **cent account** or with a broker whose gold contract is small enough. Check *Symbol → Specification* first.

## Setup

1. Copy the `.mq5` to *File → Open Data Folder → MQL5/Experts*, compile in MetaEditor (F7).
2. Attach to the gold **M1** chart and set `InpTradeSymbol`.
3. Set `InpExtraCostPts` to your round-trip commission in points.
4. Backtest with **"Every tick based on real ticks"**. Expect few trades; the cost gate skips marginal setups.

**No backtest or live results are published.**
