# Apex NAS100 Adaptive Scalper (MT5)

A modular, self-adjusting MQL5 scalping system for NAS100 (US100 / USTEC / NASDAQ CFDs), built to
institutional logic: **Delta Flow + Money Flow + Volume Profile + multi-anchor VWAP + Price-Action
structure + AMD phase tracking + DOM(Level-2) imbalance + regime engine**, all fused by a weighted
confluence engine with prop-firm-grade risk controls.

> **Honest disclaimer:** No EA can *guarantee* 10%/month with <10% drawdown — markets don't owe anyone
> a return. This system is *engineered toward* that target: it only trades when many independent
> evidences align, it sizes every trade from risk, and it hard-stops before prop-firm limits break.
> Forward-test on demo for 4–8 weeks before any live or prop use.

---

## 1. What you get

```
Include/Apex/*.mqh          12 shared modules (analytics, risk, execution, relay)
Experts/Apex_NAS100_EA.mq5  the EA (auto-trade, signals-only, or both)
Indicators/Apex_NAS100_Indicator.mq5  visual twin: VWAPs, profile, OB/FVG zones, dashboard
Presets/Apex_PropFirm.set   tuned for prop rules (5% daily / 10% overall class)
Presets/Apex_Regular.set    personal account preset
```

## 2. Install

1. Copy `Include/Apex` → `<MT5 data folder>/MQL5/Include/Apex`
2. Copy `Experts/Apex_NAS100_EA.mq5` → `MQL5/Experts/`
3. Copy `Indicators/Apex_NAS100_Indicator.mq5` → `MQL5/Indicators/`
4. Open MetaEditor → compile EA and indicator (F7). 0 errors expected; warnings are documented.
5. Drag EA onto a NAS100 chart (any timeframe — it reads M5 internally), load a preset, enable Algo Trading.

## 3. Decision engine (what a trade needs)

Every M5 bar close, the engine scores LONG and SHORT from 8 weighted evidence groups:

| Weight | Group | What it checks |
|---|---|---|
| 20 | Market Structure | BOS/CHoCH direction, premium/discount, bullish/bearish OB & FVG touches, EQH/EQL sweeps |
| 15 | VWAP stack | price vs daily + weekly + quarterly VWAP (alignment = trend permission) |
| 15 | Delta Flow | per-bar buy/sell pressure, cumulative delta slope, delta divergences, delta flips |
| 12 | Volume Profile | POC/VAH/VAL reactions, LVN breakout room, HVN rejection |
| 10 | Money Flow | MFI side & slope, money ratio, high-traded-node support/resistance |
| 10 | AMD phase | Accumulation / Manipulation / Distribution alignment with direction |
| 10 | Regime | trend strength, efficiency ratio, momentum, volatility factor |
| 8  | Order book | **3-tier free Level-2**: native MT5 DOM when the broker publishes it; otherwise a **synthetic order book** rebuilt from the raw tick stream (aggressive buy/sell volume-at-price ladder + order-flow imbalance OFI); tape-speed fallback |

**Book tiers** (shown on the dashboard as DOM / SYNTH / TAPE): with a real DOM feed, scoring uses
true depth imbalance + OFI. Without one, the EA classifies every tick's aggression
(last ≥ ask = aggressive buy, ≤ bid = sell, mid-move rule otherwise) and aggregates it into a
rolling price ladder (`InpBookSynthWindowSec`, `InpBookLadderBins`): buy aggression stacked below
price = synthetic bid support, sell aggression above = synthetic ask resistance. OFI
(simplified Cont–Kukanov bid/ask-step imbalance) works on **any** feed, so group 8 never goes blind.

Score ≥ adaptive threshold (base 70–72, **+10 in ranges, −5 in breakouts, +5 in Asia, blocked in
dead-quiet volatility**) → trade. The losing side must trail by ≥8 points, killing coin-flip entries.

**Stops** go beyond the invalidating structure (swing low / order-block edge), clamped to
0.8–2.2×ATR. **Targets** at 1R / 2R / 3R (scaled by volatility): TP1 closes 50% and moves SL to
break-even + buffer, TP2 closes another 30%, the runner trails by ATR. **Time-stop**: any scalp that
hasn't resolved within `InpTimeStopBars` bars (default 12 = 1h on M5, 0 disables) is closed at
market — validated as a DD-reducer in the research harness (see §8).

## 4. Prop-firm safety layer (always on)

- **Daily DD guard**: halts at 90% of `InpMaxDailyDDPct` (e.g. 4.5% input → halt ≈4.05%).
- **Overall DD guard**: halts at 90% of `InpMaxOverallDDPct`, measured from first-run (or configured)
  baseline balance. Daily halt resets next server day; overall halt needs a manual reset
  (`APEX_RISK_RESET` global variable) — by design.
- **Consistency cap** (prop mode): stops new entries once today's profit ≥ `InpDailyProfitCapPct`.
- **Guards**: max trades/day, 1 concurrent position, max spread filter, news windows, broker-rollover
  blackout, Friday cutoff, no weekend/Asia unless enabled.
- State persists across terminal restarts via GlobalVariables + file fallback.

## 5. Signal relay (trade it anywhere)

On every signal the EA writes, to `MQL5/Files/ApexSignals/`:

- `signal_YYYYMMDD_HHMMSS_BUY.json` — full payload: symbol, direction, entry, SL, TP1/2/3, RR,
  score vs threshold, regime, session, AMD phase, ATR, spread, **human-readable reasons**, expiry.
- `signals.csv` — append-only log of every signal.
- MetaQuotes push notification (enable in Tools→Options→Notifications) so signals hit your phone.

Any copier or manually-traded prop account can mirror the JSON payload 1:1 — entry, SL and all three
TPs are explicit. `InpMode=1` makes the EA signals-only (zero trading) if you want it purely as a
signal engine for accounts/platforms it can't touch.

## 6. Key inputs to check FIRST

| Input | Why |
|---|---|
| `InpGMTOffset` | Session logic depends on it. EET brokers: 2 (winter) / 3 (summer). |
| `InpNewsWindowsCSV` | Server-time `HH:MM-HH:MM;...`. Defaults cover US CPI/NFP windows (13:30/15:00 EET). Add FOMC 19:00-19:15. |
| `InpMaxSpreadPoints` | 120 default; raise for wide-spread brokers, lower for raw feeds. |
| `InpPropFirmMode` | Enables the consistency cap + stricter interpretation. |
| `InpMode` | 0=trade only, 1=signals only, 2=both. |

## 7. Backtesting honestly

- Strategy Tester → "Every tick based on real ticks", M5 NAS100, variable spread, include at least
  12 months that contain a trend leg, a chop leg and a crash leg.
- DOM depth does not exist in the tester — the book module runs on its synthetic-ladder/tape tiers
  there, so live results can differ (usually slightly better fills, occasionally worse).
- Judge by: profit factor ≥ 1.6, max DD < 8%, recovery factor ≥ 3, and a flat-ish equity curve in
  REGIME_RANGE months. If a month fails, tune `InpMinScoreBase` ±3 — not the stop logic.

## 8. Research log — what was tested, accepted, rejected (and why)

A Python research harness ports the full decision chain (same weights, adaptive threshold, structure,
FVG/OB, AMD, regime, SL/TP/partials, risk gates) onto a calibrated multi-regime NAS100 5-min generator
(trend/range/breakout/quiet regimes, GARCH vol clustering, fat tails, session vol shape). No real
intraday feed was reachable from the build environment, so these results validate **mechanics, risk
behavior, and robustness across regime draws — NOT real-market edge**. 6 Monte-Carlo seeds × 260 days:

| Change | Verdict | Evidence (6 seeds, vs baseline) |
|---|---|---|
| Baseline risk system (DD halts, sizing) | **works** | max DD 1.5–5.5% incl. a losing-regime seed; halts triggered correctly |
| Range-trigger trading mode (+achievable-max score normalization) | **REJECTED** | hurt 3/3 test seeds (−0.2 to −1.0%/yr each) |
| Consecutive-loss daily cooldown | **REJECTED** | zero effect (never triggered at 0.15 trades/day); added complexity only |
| **Time-stop: exit scalps stale after 12 bars** (`InpTimeStopBars`) | **ACCEPTED** | mean ret +1.83→+2.12%, mean DD 2.85→2.13%, worst seed −3.15→−2.42%; theory: scalp momentum decays |

Trade frequency in-sim was ~0.15–0.2/day at MinScore 70 — the engine is deliberately ultra-selective;
whether to relax `InpMinScoreBase` (±3 steps) must be decided on **real** MT5 backtests, not synthetic data.

## 9. Architecture (for developers)

See `SPEC.md` in the repo — it is the exact interface contract every module implements. Modules are
independent classes (CDeltaFlow, CMoneyFlow, CVolumeProfile, CVwapEngine, CMarketStructure,
CAMDTracker, COrderBookFeed, CRegimeEngine, CRiskManager, CTradeExecutor, CSignalEngine,
CSignalRelay). You can reuse any of them in your own EA by including the header.

**Data limitations, stated plainly:** CFD feeds rarely carry real futures volume — tick volume is the
proxy (research consistently shows ≈90% correlation to real volume on index products). Delta is
estimated per bar (close-location-in-range) and tick-rule on the live bar. Level-2 is 3-tier: native
DOM where the broker publishes it; otherwise the synthetic tick ladder + OFI above; worst case, tape
speed. DOM also does not exist in the Strategy Tester — there the book module runs on synthetic/tape
tiers, so live results can differ (usually slightly better fills, occasionally worse).
