# Miroscope — BUILD PROGRESS

Live build log. Small saved steps. If a session compacts, resume from here.

Product: MT5 Expert Advisor that trades ONLY the 1-2-3 reversal, manages trades
(not just alerts), multi-timeframe bias (D1->H1, H4->M15), scale-in entries, partial +
runner (15-off/5-running = 75/25), pre-entry invalidation that cancels a setup.

SAFETY: live trading is OFF by default (`InpEnableLiveTrading=false`). No broker connect,
no account creds, no real orders until Michael explicitly authorizes. Not compiled/tested
yet — MQL5 compiler is not on this box. Every claim stays honest: written != compiled !=
backtested != live.

Main file: source/Miroscope.mq5

## Checklist
- [x] Preserve the original submitted scanner (source/Tommy-123_Pattern_Scanner_V8.0_Full.mq5, untouched)
- [x] Phase 0: code review, all findings proven (PHASE0-REVIEW.md)
- [x] Phase 1: cleaned scanner P1, defects fixed (PHASE1-NOTES.md, tests/TEST-RESULTS.md)
- [x] Phase 2: executing EA Miroscope_EA_P2.mq5 (detector + bias engine + setup objects + on-chart display)
- [x] Phase 2: trade execution HARD-GATED OFF (InpLiveTrading=false AND InpAllowOrders=false, all 12 order sites audited)
- [x] Phase 2: EA logic ported to Python and executed (ea/TEST-RESULTS-P2.md)
- [x] Phase 3: risk engine (risk/risk_engine.py) + seeded simulation (risk/RISK-RESULTS.md)
- [x] Phase 4: backtest on REAL historical data (100 trades, honest loss — see report)
- [ ] Phase 4: paper trading on live market data — BLOCKED (no broker, no MetaTrader, no demo account)
- [ ] Phase 4b: strategy-tuning loop (backtest says current spec loses; trading decisions for Michael)
- [ ] Phase 5: live deployment — NOT AUTHORIZED, never without Michael's explicit go
- [x] Phase 6: runbook + handoff docs (docs/RUNBOOK.md)
- [ ] Compile in MetaEditor — NOT DONE (no MQL5 compiler on this box; needs Michael)

## Log
- 2026-09-14 21:11 EDT — Starting real build from the 15 requirements + the submitted scanner.
  ChatGPT draft not needed as a base; building fresh from spec.
- 2026-09-17 08:09 EDT — Client-facing build plan written (Miroscope-Build-Plan.md + PDF):
  7 milestone-gated phases, Phase 0 done through Phase 6 handoff, honest week estimates,
  no live trading until paper trading passes. Real phases, no padding.
- 2026-09-22 01:30 EDT — Project closed per Michael (deal off, no payment, no contract).
  Final archival package: full May-September correspondence reviewed, sanitized archival
  report added (docs/Miroscope-Archival-Report-2026-09-22.md + PDF), obsolete "(TD)"
  naming fixed, both document PDFs regenerated from current markdown and visually
  inspected page by page. ZIP rebuilt and integrity-checked.
- 2026-09-22 02:05 EDT — Michael ordered the build restarted: phases 0 and 1, internal
  engineering only, live trading stays OFF, no broker, no real money. Work lives in the
  Miroscope side chat. Phase 0 re-verified against the actual source (was previously
  recorded done): exactly 2 duplicate function definitions confirmed, both hard MQL5
  compile errors, both resolved per the author's own "SINGLE DEFINITION" comments.
  Findings: docs/PHASE0-REVIEW.md. Phase 1 delivered: source/Miroscope_Scanner_P1.mq5
  (1,703 lines, 36 functions, zero duplicates, braces/parens balanced, scanner only,
  zero trade-execution calls, alert logic intact). Static audit only: NO MQL5 compiler
  on this box, "compiles clean" NOT claimed, MetaEditor check still required. Detection
  core ported to Python (tests/test_123_detection.py) and EXECUTED against synthetic
  OHLC: 16/16 pattern cases pass (5 bullish BUY, 5 bearish SELL, 3 no-break near-miss
  silent, 3 no-rejection near-miss silent), entry/SL/TP math verified at realized RR
  3.0000. Raw core on 80 chop bars: 8 pattern-shaped hits with all gates forced open;
  the real scan layers trend/zone/RSI/volume/ML gates in front. Full results:
  tests/test-results-2026-09-22.txt.
- 2026-09-22 02:10 EDT — CORRECTION, own the miss. The 02:05 entry above was my
  first pass in the side chat and it was shallow: it caught only the duplicate
  functions and wrongly said "everything else is structurally sound." A deeper
  parallel pass (from the main chat, artifacts at the build root) found four
  more real defects, and I verified each one against the source myself before
  accepting it: (F2) SortPairsByPriority reorders g_pairs[] while indicator
  handles stay keyed to the old order, so ATR/RSI/MA get attributed to the
  wrong symbols from tick 2 on; (F3) with ML off, mlConfidence=0.5 < 0.55 gate,
  so STRONG/FULL statuses are unreachable; (F4) CheckRSICondition is a
  tautology, always true for any RSI 0-100 (the working gate is the inner one
  in DetectPatternForPair); (F5) GetPipSize 4-digit branch returns point*100,
  100x off; (F6) six vestigial inputs/globals declared but never read.
  Canonical review: PHASE0-REVIEW.md (build root). P1 was rebuilt from the
  original by build_p1.py with fixes for F1, F2, F3, F5 + Miroscope rebrand:
  source/Miroscope_Scanner_P1.mq5 (57,281 bytes, 1 def per function,
  g_displayOrder sort fix, ML gate fix, pip fix, zero trade calls — all
  re-verified by grep on disk). Canonical notes: PHASE1-NOTES.md. Canonical
  simulation: tests/TEST-RESULTS.md + tests/test_scanner_logic.py (24/24
  textbook detections at the exact bar, 0 wrong-direction, 0 false fires on 4
  malformed controls, all four defects reproduced numerically and fixes
  verified). My shallow docs/PHASE0-REVIEW.md was deleted (it was wrong);
  docs/CHECKSUMS-P1.txt regenerated against the real artifacts. Standing
  honest boundary unchanged: no MQL5 compiler here, MetaEditor compile check
  still required before this touches a live terminal.
- 2026-09-22 02:35 EDT — Michael: keep building through the phases until a genuine
  wall. Phase 2 delivered: ea/Miroscope_EA_P2.mq5 (649 lines, 24,262 bytes) — 1-2-3
  detector on trigger TF, bias engine (lane 0: D1 bias/H1 trigger, lane 1: H4 bias/M15
  trigger), setup objects (entry/SL/TP1 1.5R/TP2 3R/invalidation/scale-in), scale-in
  entries (60/40 risk split), partial-plus-runner (75% at TP1, SL to BE+0.1R, runner to
  TP2), pre-entry invalidation kill, 12-bar expiry, 21:00 session cutoff + flatten,
  -3% daily loss halt, on-chart display. Trade execution HARD-GATED OFF: InpLiveTrading
  AND InpAllowOrders must both be true (both default false); all 12 order call sites
  audited behind the gate. Manual audit: braces 62/62, parens 360/360, 25 functions,
  zero duplicates. NOT compiled (no MQL5 compiler here). EA decision logic ported to
  ea/test_ea_logic.py and EXECUTED: T1 12/12 detected with setup values exact to 1e-9;
  T2 0 against-bias setups; T3 invalidation kill at 0.0R; T4 expiry at 0.0R; T5 full
  lifecycle (fill, scale-in, TP1 partial, runner TP2) at +3.025R; T6 scale-in then SL
  at -1.0R combined (correct risk allocation); T7 lane engine 46+84 setups, 100%
  direction/bias agreement. Full results: ea/TEST-RESULTS-P2.md. Notes: PHASE2-NOTES.md.
- 2026-09-22 02:40 EDT — Phase 3 delivered by build worker: risk/risk_engine.py
  (stdlib only, import-safe) — position sizing from risk %, 60/40 scale-in plan,
  75/25 partial-plus-runner, BE+0.1R, 12-bar expiry, invalidation kill, 21:00 session
  cutoff, -3% daily loss halt, 5 setups/day cap. Seeded simulation (seed 20260922,
  $10k, 1% risk, 40 synthetic setups): lot samples 0.160-0.355 (16.9-37.6 pip stops);
  11 killed pre-entry, 8 expired, 21 filled, 10 scale-ins; exits: 8 full SL, 6
  TP1+TP2, 4 TP1+BE, 3 TP1-then-BE; total -$532.00 on synthetic random resolutions
  (says nothing about edge — real verdict is Phase 4). Docs: risk/RISK-ENGINE.md,
  risk/RISK-RESULTS.md. All functions spot-verified against spec after delivery.
- 2026-09-22 03:05 EDT — Phase 4 data hunt (build worker): real data obtained.
  backtest/data/eurusd-h1.csv — 10,605 H1 rows, 2025-01-01 to 2026-09-22 UTC, Yahoo
  Finance EURUSD=X (volume unusable, FX spot). Plus 1 validated day of Dukascopy M1
  (cross-checked vs Yahoo 1m, ~3 pip mean diff). histdata.com POST hangs, stooq
  unreachable, Dukascopy throttles after ~15 reqs (full 20-month M1 pull infeasible).
  See backtest/data/DATA-SOURCE.md.
- 2026-09-22 03:10 EDT — Phase 4 BACKTEST ON REAL DATA. backtest/run_backtest.py runs
  the full ported stack (P1 detector + P2 setup/lifecycle + P3 risk) over the 20-month
  EURUSD H1 set, lane 0 (D1 bias -> H1), $10k, 1%/setup, 21:00 UTC cutoff, 5/day cap,
  -3% daily halt. No spread/commission/slippage modeled. RESULT: 100 trades, 31 wins,
  win rate 31.0%, profit factor 0.78, expectancy -$13.82/trade (-0.139R), max drawdown
  27.59%, return -13.82% (final $8,618.17). Exit diagnostic: 69 full SL (-1R), 16
  TP1+TP2 (up to +3.02R), 15 TP1 then runner stopped at BE (~+1.4R); median trade -1.0R;
  max 2 concurrent. HONEST READ: as specified, the strategy loses on this dataset —
  31% reach TP1 but only 16% ever see TP2 while 69% take the full stop; the 1.5R/3R
  structure needs a win profile the pattern is not producing here. Per the build plan
  this means fixing the logic (target/stop/gate tuning, re-run on same data), which is
  a trading-decision loop for Michael, not started here. Paper trading BLOCKED: no
  broker, no MetaTrader, no demo account in this environment. Full report:
  backtest/BACKTEST-REPORT.md. Phase 6 runbook: docs/RUNBOOK.md.
# 2026-09-25 06:45 EDT — VARIANT TESTING LOOP AUTHORIZED (Michael)
Michael pasted 11 ChatGPT strategy variants (1-2-3 pattern family). Directive:
port each TESTABLE variant into a Python harness, run on the SAME 20-month
EURUSD H1 dataset as the Phase 4 baseline, keep what survives, cut the rest.
Research proposes, the backtest disposes. Coordinator dispatched; one 15-min
watchdog (miroscope-variants-watchdog) standing by. No live trading, no broker,
no real money anywhere in this loop.
- 2026-09-25 ~11:00 UTC — Variant backtest loop COMPLETE (coordinator subagent).
  Tested 8 H1 ChatGPT strategy variants (V1a/V1b/V2/V3/V4/V5/V7/V9/V11) on the same
  10,605-bar EURUSD H1 dataset as Phase 4, $10k / 1% risk, no spread (comparable).
  Engine: variants/run_variants.py (stdlib only, deterministic; indicators and
  partial-fill accounting unit-verified; no lookahead: fractals confirmed 2 bars late).
  Ranked by expectancy: V3 +0.635R (PF 5.13, n=13), V7 +0.183R (n=3), V11 +0.068R
  (PF 1.12, n=23), V4 -0.029R, V5 -0.068R, V2 -0.088R, baseline -0.139R, V9 -0.396R;
  V1a/V1b 1 trade each (untestable: RSI-at-P1 filter passes ~1-15x in 20 months).
  VERDICT: no variant beats the baseline convincingly. V3 is interesting but n=13
  (winners cluster in the 2025 EURUSD rally; needs out-of-sample data). V11 marginally
  positive at n=23. V4 breakeven; V2/V5/V9 lose; V1/V7 untestable as specified.
  M15 variants V6/V8/V10 NOT tested (no M15 data; not faked). Nothing here justifies
  paper trading. Full report: variants/VARIANTS-REPORT.md. Plan: variants/PLAN.md.
  Progress log: variants/PROGRESS.md. STOPPED per brief: no paper trading, EA untouched.

# 2026-09-25 07:00 EDT — ROUND 2 AUTHORIZED (Michael)
Round-2 ChatGPT workup received (10 experiments, pre-registered ladders, overfitting
discipline section). Directive: port and backtest all round-2 runs on the same
dataset/accounting as round 1. Spec: variants/ROUND2-SPEC.md. ~20 runs: V3 family x4,
V1 ladder x2, V11 slope ladder x3, V4 3x3 timing/depth matrix x9, V2-EMA20, V9 control.
Report must show expectancy CURVES across ladders (stable plateau beats isolated peak).
Coordinator dispatched; one 15-min watchdog (miroscope-variants-r2-watchdog). No live
trading, no broker, no real money.

# 2026-09-25 ~07:05 EDT — ROUND 2 COMPLETE
All 20 round-2 runs backtested on the same EURUSD H1 data/accounting as round 1.
Engine extended (not rebuilt): variants/run_variants.py gained round-2 classes;
round-1 classes untouched and re-run to exact reproduction. Mechanization per
variants/PLAN-R2.md (round-2 "1 tick" = 0.01*ATR14 per spec; no lookahead).
Unit-checked one run per family before batching; R math spot-verified by hand.
Ranked by expectancy: V3-L5 +0.502R (PF 2.76, n=120), V1-RSI45 +0.490R (n=30),
V3-L3 +0.465R (n=142), V3-NX +0.442R (n=13, no-expiry control),
V1-RSI40 +0.394R (n=12), V2-EMA20 +0.378R (PF 2.24, n=107), V9c +0.172R (n=52),
V4 matrix +0.031..+0.119 (D0.25 best in all 3 rows, weak ridge), V11-A/B/C
identical +0.111R (n=30; slope knob non-binding). V3-NX shows the 18-bar expiry
was worth ~+0.19R of round-1 V3's +0.635R; entry still positive without it.
Sensitivity curves: V1 monotonic (2->12->30 trades, expectancy holds/rises),
V3 threshold 5vs3 stable plateau, V11 flat (dead knob), V4 gentle D0.25 ridge.
NO isolated single-rung peak anywhere: overfit discipline held, curves reported.
VERDICT: first triple-digit-sample positives of the program (V3-L5, V3-L3,
V2-EMA20). V1-RSI45 and V9c alive but thin (n=30/52). All in-sample; nothing
justifies paper trading. Next honest step (Michael's call, NOT started):
out-of-sample (more pairs/years) on V3-L5/L3 and V2-EMA20. Full report:
variants/VARIANTS-REPORT-R2.md. Plan: variants/PLAN-R2.md. Progress:
variants/PROGRESS-R2.md. STOPPED per brief: no paper trading, EA untouched.

# 2026-09-25 07:20 EDT — ROUND 3 AUTHORIZED (Michael)
Round-3 ChatGPT validation protocol received: pre-registered SURVIVED/INCONCLUSIVE/DEAD
thresholds (+0.10R, PF 1.30, >=20 trades every pair, >=6/8 positive pairs, worst pair > -0.25R),
fixed 8-pair test order, trap protocols, 3 minimal robustness variants, decision tree for round 4.
Directive: freeze the protocol and run it. Spec: variants/ROUND3-SPEC.md (locked, no param changes).
Downloaded 8 OOS H1 pair files from Yahoo (~10.5k bars each, full 07-17 UTC coverage).
64 runs: 5 variants x 8 pairs + 3 robustness x 8 pairs. Coordinator dispatched; one 15-min
watchdog (miroscope-variants-r3-watchdog). No live trading, no broker, no real money.

# 2026-09-25 11:23 UTC — ROUND 3 OOS VALIDATION COMPLETE (coordinator)
64 runs (5 variants + 3 robustness x 8 unseen pairs). Pre-registered verdicts:
V3-L5 SURVIVED (+0.389R, PF 2.15, 964 trades, 8/8 pairs positive),
V3-L3 SURVIVED (+0.375R, PF 2.08, 1,158 trades, 8/8 positive),
V2-EMA20 SURVIVED (+0.285R, PF 1.79, 915 trades, 8/8 positive),
V1-RSI45 INCONCLUSIVE (USDCAD n=19, one trade short of the 20 minimum),
V9c INCONCLUSIVE (agg PF 1.21 below the 1.30 bar). All robustness perturbations
held; no worry-condition triggered. Report: variants/VARIANTS-REPORT-R3.md.
Decision tree points to round 4 (temporal validation of V3-L5 + V2-EMA20) —
NOT started; Michael's call. No live trading, no broker, no real money.

# 2026-09-25 07:33 EDT — ROUND 4 AUTHORIZED (Michael)
Round-4 ChatGPT temporal-validation protocol received: 3 variants (V3-L5, V2-EMA20, V3-L3),
V1-RSI45 benched (no post-selection relaxation), EURUSD excluded from verdicts (reference only),
4 chronological blocks with entry-block attribution, gold second-asset-class test for all three,
tightened TEMPORALLY ROBUST/INCONCLUSIVE/FRAGILE verdicts, 10 round-5 branches.
Locked in variants/ROUND4-SPEC.md BEFORE any run. Downloaded gold-h1.csv (GC=F, 9,837 bars).
~96 run-units: 3 variants x 7 FX pairs x 4 blocks + EURUSD reference + 3 x gold x 4 blocks.
Coordinator dispatched; one 15-min watchdog (miroscope-variants-r4-watchdog).
No live trading, no broker, no real money.

# 2026-09-25 07:41 EDT — ROUND 4 TEMPORAL VALIDATION COMPLETE (coordinator)
27 runs (3 variants x (7 FX pairs + EURUSD reference + gold), full-series runs with
entry-block attribution, frozen definitions, EURUSD hard-excluded from verdicts).
Pre-registered FX verdicts: V3-L5 TEMPORALLY ROBUST (4/4 blocks pass, agg +0.402R,
PF 2.21, 7/7 pairs positive, 830 trades); V3-L3 TEMPORALLY ROBUST (28/28
pair-block cells positive, agg +0.376R, PF 2.09, 1,000 trades); V2-EMA20
TEMPORALLY ROBUST (4/4 blocks pass, agg +0.285R, PF 1.79, 805 trades; weakest
cells in short block D, none breaching the -0.50 guard). Gold: V3-L5
GOLD-REJECTED (1/4 blocks meet N>=30; expectancy positive in all 4 blocks),
V3-L3 GOLD-INCONCLUSIVE (3/4 blocks pass), V2-EMA20 GOLD-REJECTED (2/4 blocks
meet N>=30; expectancy positive in all 4). Gold rejections are sample-size, not
sign; not used to rescue or condemn FX. Report: variants/VARIANTS-REPORT-R4.md;
raw trades: variants/results-r4.jsonl; verdicts: variants/verdicts-r4.json.
Round-5 branches firing: 1 (forward validation, frozen), 4 (threshold plateau on
new data), 8 (V2 stays FX-specific). NOT started; Michael's call. No live
trading, no broker, no real money.

# 2026-09-25 07:44 EDT — ROUND 5 LOCKED (Michael approved)
Round-5 ChatGPT forward-validation protocol received and locked in variants/ROUND5-SPEC.md BEFORE any forward bar.
Archive extended to full round-5 freeze: backtest/data/archive-2026-09-25/ now holds raw data + frozen specs (R2-R5) + code + reports + results, 24 files SHA-256 hashed in MANIFEST-ROUND5.txt, sealed read-only.
CORRECTION recorded: round 3 ran 8 non-EURUSD pairs; round 4 ran 7 (EURJPY dropped in transcription, verdicts stand on pairs tested); round 5 forward universe = all 8 non-EURUSD pairs.
Forward window: 2026-09-21 → 2027-03-31 fixed. Formal verdict needs 6 complete months + N>=150/variant + 15 trades on 7/8 pairs. CONFIRMED: E>=+0.10R, PF>=1.30, 6/8 positive pairs, worst pair >-0.25R. Plateau test: both L3/L5 confirmed + |ΔE|<=0.10R. Rejection = permanent retirement, one audit diagnostic only, no new variants.
Interim looks monthly (first 2026-10-31), descriptive only. Gold excluded from round 5.
No forward runs possible yet — forward data accumulates from 2026-09-21 onward.
Paper-trading gate design specified in workup; remains a human decision, not started.
Video request still pending (~1 hour mark).

# 2026-09-30 14:42 EDT — VARIANCE LAB LIVE (Michael directive: never lose progress)
- P2B was the original attempt. It had an error code and was retired. P2C is the sole current base and control. Do NOT attribute old demo trades to P2B.
- P2D built 2026-09-30: exact P2C with tradedBias = -BiasDirection() before DetectPattern(). Magic 20260930. Both gates false. Source: ea/Miroscope_EA_P2D.mq5 (1,017 lines). Page: /variance/p2d/. Compile pending, backtest pending, verdict pending.
- P2E built 2026-09-30: exact P2C with raw bias untouched, baseSig inverted to sig = -baseSig after DetectPattern(). Magic 20260931. Both gates false. Source: ea/Miroscope_EA_P2E.mq5 (1,019 lines). Page: /variance/p2e/. Compile pending, backtest pending, verdict pending.
- P2D vs P2E are genuinely different: P2D changes which signal qualifies (bias flip before detection). P2E keeps the qualifying signal and reverses only the resulting action.
- Variance Lab: /variance/ lists control P2C (10,605 H1 bars, 100 trades, 31% win, PF 0.78, expectancy -0.139R, max DD 27.59%, net -13.82%) and both variants.
- Vault: /vault/ password-protected (splash) holds every Miroscope document. Cloudflare is the vault, local disk is scratch.
- Live trading remains OFF. No broker, no real money. No compile claimed (no MetaEditor here).
