# P3-S22 — TERMINAL INDICATOR VERIFICATION (non-visual, deterministic) ```text Date : 2026-08-25 Session : P3-S22 — TERMINAL INDICATOR VERIFICATION Scope : verify the existing SniperGold MQL5 runtime (Algo Forge / SniperGold SMC Pro+ refactor: Engine1..Engine3, F1 events, F2 zones, F3 Candidate Setup, F4 MTF gates) compiled and executed inside MetaTrader 5 Terminal, using MACHINE-READABLE evidence only (journal/structured traces/CSV/independent oracle). NO image analysis, NO OCR, NO visual pass/fail. Method : CODE_VERIFICATION_AND_SILENT_BUG_POLICY_v1.md Result : B — PASSED WITH LIMITATIONS (core runtime verified; some environmental dimensions unverified — see §S, §T). Next : NO automatic advance. P3-S23 NOT STARTED (owner decision). ``` --- ## A. Latest handover used ```text docs/SESSION_HANDOVER_2026-08-25_P3_S21_R_RETROSPECTIVE_SILENT_BUG_VERIFICATION.md (newest handover at start; predecessor chain traced for continuity: S21.2 -> S21.1 -> S20 -> S19 -> S18 -> S17R2 -> S16). docs/CODE_VERIFICATION_AND_SILENT_BUG_POLICY_v1.md (read and applied). ``` ## B. Starting SHA ```text P3_S22_START_SHA : d5523ee97dbe9f7fd73de44ae3e90420246e6844 VERIFIED: local HEAD == origin/main == d5523ee, branch main, working tree CLEAN, no stash, no untracked files, origin = https://forge.mql5.io/chiki2bum2/SniperGold_ML.git ``` ## C. Final SHA ```text P3_S22_FINAL_SHA : f90f878ccfb2ddfdb3de320fa8de33824a46af01 (main == origin/main, working tree CLEAN at close) ``` ## D. Runtime dependency graph (exact, from source) ```text Terminal indicator entry point: MQL5/Indicators/AlgoForge/AF_Engine3_Display.mq5 (indicator_buffers=0, indicator_plots=0) └─ include (Engine3 render) └─ AF_Engine2_Display.mqh (AF_BuildDisplayData) └─ AF_Engine2_Aggregator.mqh (AFAggregator facade) └─ AF_Engine2_Agents.mqh (F1 events + F2 zones + 4 agents N/C/E/P) ├─ AF_Defines.mqh (constants, TF mapping) │ └─ AF_Attribution.mqh (attribution header) └─ AF_Engine1_MTFData.mqh (MTF bar cache, closed-bar lock) F3 Candidate Setup runtime (separate layer, NOT in display indicator): MQL5/Include/AlgoForge/AF_Engine2_Setup.mqh (AFSetupEngine: lifecycle, identity registry, one-entry, gates; consumes semantic inputs h4/m30/sweep/choch/zone/m15/m3/entry/score) └─ includes AF_Engine2_Agents.mqh (same chain as above) Runtime consumers exercised in P3-S22: MQL5/Experts/AlgoForge_Engine1_UnitTest.mq5 (Engine1 cache tests) MQL5/Experts/AlgoForge_Engine2_UnitTest.mq5 (agents + aggregator + F3 synthetic T6/T7) MQL5/Experts/AlgoForge_Engine3_UnitTest.mq5 (display data + render) AlgoForge_S22_F3_Parity.mq5 (DISPOSABLE P3-S22 harness, deleted after run; source preserved in Common scratch) Not part of the verified runtime (legacy/ML path, NOT executed): MQL5/Experts/AlgoForge_Backtest_Baseline.mq5 (MLP 19->12->2, SniperGold_ML.mqh, has OrderSend in mode 1 -> NOT run, Phase 17 no-trading) FEATURE_CONTRACT.md (research contract; not linked by the indicator runtime) ``` F1 (events): `AF_DetectSweepEvent`, `AF_DetectChochEvent` (AF_Engine2_Agents.mqh) — onset + dir, stateless per closed bar (P3-S.11 semantics). F2 (zones): `AF_FindOrderBlock`, `AF_FindFVG`, `AF_OBZoneState`, `AF_FVGZoneState`, `AFZoneState` (P3-S.12 semantics: UNMITIGATED/PARTIALLY_FILLED/FULLY_MITIGATED, invalidation=full-fill, newest-active-only). F3 (Candidate Setup): `AFSetupEngine` (P3-S.13 frozen contract, 25 spec cases). F4 (MTF): `AFEngine1MTF` slots H4/M30/M15/M3 (AF_E2_TF_S1..S4) with closed-bar lock; F3 gates h4==m30==direction (OD-1), conflict -> BLOCKED (OD-4). Buffers: NONE (indicator_buffers=0). Chart objects: prefix `AF3_` (OB/FVG rectangles, structure lines, swing labels, PD bands, PDH/PDL/PWH/PWL levels, dashboard) — created only by Engine3 render. Logging: Print/PrintFormat journal (prefixes AFTEST/AFTEST2/AFTEST3/S22F3). External files: only AlgoForge_Backtest_Baseline writes CSV (not run here); the verified runtime writes NO files (parity harness printed to journal only). Trading: none in the verified runtime. ## E. Compiler / build information ```text MetaEditor build : 6140 (MQL5 compiler, target AVX512 + FMA3) Compiled (all 0 errors / 0 warnings): AF_Engine3_Display.mq5 -> PASS AlgoForge_Engine1_UnitTest.mq5 -> PASS AlgoForge_Engine2_UnitTest.mq5 -> PASS AlgoForge_Engine3_UnitTest.mq5 -> PASS AlgoForge_S22_F3_Parity.mq5 -> PASS (disposable harness) Source SHA : d5523ee (frozen; compile does not modify source) Classification : COMPILE PASS ``` ## F. Terminal environment ```text MetaTrader 5 build 6140; server HFMarketsGlobal-Demo; login 49488474 (demo); hedging; account read-only by policy (no orders sent). CPU Intel Xeon Gold 5220; Windows 11 (KVM); UTC+0. ``` ## G. Symbol / timeframe ```text Symbol : XAUUSD (Gold Spot, XCCY, digits=2, point=0.01, spread float) Period : M15 (agent TFs hardcoded: S1=H4, S2=M30, S3=M15, S4=M3) ``` ## H. Data source ```text Terminal broker history (HF Markets demo) via AFEngine1MTF CopyRates cache (closed-bar lock; bars[0] = newest closed bar). Tester runs: model "every tick" (Model=0), Visual=0, XAUUSD M15, 2026.08.01–2026.08.11/20. Research population reference (694/686/594/92) comes from the committed research dataset pipeline (P3-S16..S21.R), not from this Terminal session. ``` ## I. Structured observability mechanism ```text 1) Strategy Tester journal (deterministic Print traces): AFTEST / AFTEST2 / AFTEST3 / S22F3 prefixes. 2) Tester agent log file: D:\TradingTerminal\HFM Metatrader 5\Tester\Agent-127.0.0.1-3000\logs\20260825.log 3) Disposable F3 parity harness (source preserved in C:\Users\defau\AppData\Roaming\MetaQuotes\Terminal\Common\p3_s22_scratch\): replays the frozen AFSetupEngine over the canonical-oracle case inputs (F3-T01..T25) and prints per-bar outcomes; NO files, NO objects, NO trades. 4) Independent oracle: ml/p3/smc_semantic/spec_tests_candidate_setup_runtime.py (canonical_oracle = frozen F3 truth; F3SetupEngine = port contract). 5) Scratch evidence (Common\p3_s22_scratch\ and MQL5\Files\Temp\): s22_oracle_all.csv, s22_oracle_t7.csv, gen_f3_cases.py, compare_f3_final.py, mutation_tests2.py, extract_*.py, harness .mq5/.mqh. ``` ## J. F1 EVENT VERIFICATION (Phase 7) ```text Engine2 test (XAUUSD M15, 2026.08.01–08.11): T1 agents valid on every closed bar (Narrative H4 / Context M30 / Entry M15 / PriceAction M3 with buy/sell/bias/confidence/dir printed); T2 independence & determinism OK; T3 closed-bar lock OK; T4 non-repaint OK (identical output within a bar, verified on every closed bar). RESULT: PASS=16571 FAIL=0. F1 EVENT semantic layer: sweep/CHoCH {onset, dir} consumed by the F3 chain (F3-T01..T25 replay, §L) with exact agreement (0 real mismatches). Classification: F1 = EXACT at the contract level (no unexplained mismatch). ``` ## K. F2 ZONE VERIFICATION (Phase 8) ```text F2 zone state semantics (UNMITIGATED / PARTIALLY_FILLED / FULLY_MITIGATED, invalidation=full-fill, newest-active-only) verified indirectly: - Engine2 Context/Entry agents consume AF_FindOrderBlock/AF_FindFVG and report "di OB/FVG" states per closed bar (journal evidence); - Engine3 display reports ob=5, fvg=6 and zone top/bottom consistency (T1: top>=bot, bot>0, tag OB/FVG) on every closed bar; - F3 zone-stage cases (F3-T03 no-zone, F3-T17 mitigation->INVALIDATED, F3-T21 pre-entry mitigation -> no setup, wrong-direction zone T07) all reproduced EXACTLY by the terminal replay (§L). NUMERIC zone boundary parity (narrow/wide/boundary-touch vs a dedicated Python zone oracle on identical bars) was NOT re-run in the Terminal; F2 numeric boundary audit is recorded as verification debt (§X). Classification: F2 = core behavior verified; numeric boundary parity unverified (limitation). ``` ## L. F3 CANDIDATE SETUP VERIFICATION (Phase 9) — 25/25 CONTRACT CASES ```text Method: disposable harness drove the FROZEN AFSetupEngine with the exact canonical-oracle case inputs (F3-T01..T25) and emitted per-bar outcomes; compared field-by-field against the independent Python oracle (canonical_oracle), using the oracle's own assertion engine (_check). RESULT (terminal replay vs frozen contract): Contract assertions (exists/id/state/dir at asserted bars, blocked + reason, m3_confirmed, score, created_count, setup_ids, entry_bindings): 24/25 PASS; F3-T20 "FAIL" = harness scoping artifact ONLY (mutated future bars were fed into the same engine run, so the cumulative created_count read 2 vs the historical-scoped expected 1; the terminal engine and the canonical oracle BOTH create 2 setups on the 12-bar input, and bars 0..9 (historical) are unchanged — the future-mutation property itself is satisfied). Per-bar full-field comparison (all bars, all fields): real (contract-visible) mismatches = 0 representation-level differences = 36 rows, all with setup_exists=False on BOTH sides and identical id/blocked/m3/entry/score. These are (a) pre-sweep forming-state label: the MQL5 port emits CONTEXT_VALID with the forming direction as soon as H4/M30 gates align, whereas the oracle stays NONE until the sweep event is active; (b) 3 rows (F3-T17/T21/T22 bar 0) where the fixture input object carries a choch/zone with onset > current bar: the MQL5 port discards and restarts the forming chain, the oracle waits; the final Candidate Setup (identity, creation bar, terminal states) is identical. This input pattern (future-onset event object) is not produced by the real semantic feed (events are active as-of the closed decision bar, onset <= r by construction). Engine2 built-in F3 synthetic tests T7a..T7e (mirror F3-T01/T08/T11/ T18/T25): 5/5 PASS in the Terminal. Canonical setup entry semantics (creation-bar close, M15): the F3 layer creates on the decision bar r (monotonic M15 index) when the chain completes; creation_bar == r verified in replay (F3-T01 created at bar 6, matching oracle). Classification: F3 = EXACT (0 unexplained mismatches). ``` ## M. F4 MTF VERIFICATION (Phase 10) ```text F4 gates (h4 == m30 == direction; conflict -> BLOCKED H4_M30_CONFLICT / M15_CONFLICT) verified in the terminal replay: F3-T01 (h4=1,m30=1 -> CANDIDATE dir=1) PASS F3-T07 (gates +1/+1 vs chain -1 -> no setup) PASS F3-T08 (H4=-1,M30=+1 -> BLOCKED H4_M30_CONFLICT) PASS (blocked flag and reason exact) F3-T09 (H4=+1,M30=-1 -> BLOCKED H4_M30_CONFLICT) PASS F3-T10 (M15=-1 vs +1 -> BLOCKED M15_CONFLICT) PASS F3-T22 (context break after formation -> INVALIDATED) PASS MTF closed-bar semantics: Engine1 cache verified (T3 closed-bar lock; T3 strict descending time order across M1/M5/M15/H1; count<=Bars consistency); Engine2/3 consume H4/M30 caches with the same lock. HISTORICAL MTF boundary-timestamp parity (exact M30/H4 bar timestamps vs a Python oracle over the same history) was NOT re-run in this session: recorded as verification debt (§X). Classification: F4 = gate logic exact; historical MTF boundary parity unverified (limitation). ``` ## N. TEMPORAL / BAR-INDEX RESULTS (Phase 11) ```text Engine1 (XAUUSD M15): PASS=115070 FAIL=0. Strict descending time order (T3), closed-bar lock (T4), anti-freeze cache index (T5: CopyRates only on Bars() change), count<=Bars consistency (T6), chart-TF independence (T7). Final cache stats: M1 count=300 hc=17928; M5 count=300 hc=3589; M15 count=300 hc=1197; H1 count=300 hc=300 (deterministic, recorded). F3 replay exercised monotonic decision-bar indexing over 25 fixtures (0..44 bars), including boundary/expiry rows: F3-T04 sweep age 41 (W_sweep=40 -> expired) EXACT F3-T16 setup age 43 (W_setup=40 -> EXPIRED) EXACT F3-T05 CHoCH before sweep EXACT; F3-T06 CHoCH outside sweep window EXACT. No off-by-one, shift, or future-bar access discrepancy found. ``` ## O. TERMINAL <-> RESEARCH COMPARISON (Phase 12) ```text Machine-readable comparison table generated (Common\p3_s22_scratch\ s22_oracle_t7.csv, s22_oracle_all.csv, per-case contract checks): T7a (F3-T01) expected CANDIDATE id=1 terminal EXACT_MATCH T7b (F3-T08) expected BLOCKED terminal EXACT_MATCH T7c (F3-T11) expected valid no M3 terminal EXACT_MATCH T7d (F3-T18) expected CONSUMED 1 entry terminal EXACT_MATCH T7e (F3-T25) expected exists score .05 terminal EXACT_MATCH F3-T01..T25 contract assertions terminal EXACT_MATCH (24 direct; T20 scoping artifact, explained) per-bar full-field terminal 0 REAL mismatches; 36 representation rows (no setup on either side) Oracle independence: canonical_oracle and F3SetupEngine are the committed frozen F3 truth (spec_tests_candidate_setup_runtime.py); the comparison was executed by a DISPOSABLE Python harness that does NOT call the MQL5 runtime to produce expected values. ``` ## P. POPULATION RECONCILIATION (Phase 13) ```text Reference (research, committed): 694 total computable Candidate Setups, 686 in-scope = 594 leads + 92 follow-ons (P3-S20 accounting, re-verified by P3-S21.R). Terminal reproduction: NOT performed. The deployed runtime does not expose a full historical semantic-input replay (F1 events + F2 zones + F4 states per M15 bar) that regenerates the Candidate Setup population; the research counts were produced by the research dataset pipeline on the authoritative data. Environmental differences (broker data source, M15 history scope, session times, spread, MTF availability) preclude a direct equality claim in this session. Reconciliation status: not reconciled numerically; recorded as verification debt (§X). No unexplained population discrepancy is asserted — the population was simply not re-derived in the Terminal environment. ``` ## Q. SILENT-BUG MUTATION TESTS (Phase 14) — verifier verified ```text Mutating a DISPOSABLE copy of the comparison pipeline (never the frozen source), the full per-bar verifier DETECTED all 7 mandated classes: 1 temporal one-bar displacement DETECTED (real_diffs=2) 2 purge/causality (future setup early) DETECTED (real_diffs=1) 3 bar-order swap DETECTED (real_diffs=2) 4 MTF gate substitution DETECTED (real_diffs=1) 5 row-alignment shift-by-one DETECTED (real+aggregate) 6 duplicate setup record DETECTED (real_diffs=1) 7 missing-record DETECTED (real+aggregate) VERIFIER-STRENGTH FINDING: the sparse contract check (asserted bars + totals only) failed to detect 4/7 mutation classes; the full per-bar, per-field byte comparison is REQUIRED coverage and detects 7/7. This finding is recorded; no production file changed. ``` ## R. INDICATOR BUFFER / OBJECT STATE AUDIT (Phase 15) ```text Buffers: none (indicator_buffers=0, indicator_plots=0). Chart objects (Engine3 render, prefix AF3_): audited programmatically via Engine3 unit test T4/T5 in the tester: object creation counts per closed bar: 218, 228, 230, 232 (recorded); T5 render determinism: redraw on same bar -> identical count (PASS); dashboard panel "AF3_P_BIAS" present (PASS); PDH/PDL/PWH/PWL price levels (e.g. 4120.31 / 4028.61 / 4165.90 / 3982.66) recorded per closed bar. No image/visual inspection was used. ``` ## S. DISCREPANCIES ```text 1) F3-T20 contract-check "FAIL": harness scoping artifact only. The disposable harness fed the future-mutation bars into the same engine run; the cumulative created_count therefore read 2 while the frozen expected asserts the historical-scoped count 1. The terminal engine and the canonical oracle agree on the full 12-bar input (both create 2 setups), and the historical bars 0..9 are unchanged. NOT a runtime defect. 2) 36 per-bar representation-level rows (F3 replay): pre-formation forming-state label differences (MQL5 CONTEXT_VALID-with-direction vs oracle NONE) and 3 future-onset-input rows (MQL5 discard-and-restart vs oracle wait). In every such row setup_exists=False on both sides and id/blocked/m3/entry/score are identical; final Candidate Setup identity/creation bar/terminal states are identical. Documented; NOT contract-visible; no production impact identified. 3) Sparse `_check` coverage insufficient for 4/7 mutation classes; mitigated by the full per-bar verifier (see Q). No UNEXPLAINED mismatch exists. ``` ## T. FINAL CLASSIFICATION ```text B — PASSED WITH LIMITATIONS Compiled successfully (COMPILE PASS, build 6140, 0/0 diagnostics). Terminal execution deterministic and non-trading (0 deals, 0 trades on every run). F3 Candidate Setup runtime reproduces the frozen canonical oracle on 25/25 contract cases (0 real per-bar mismatches). F1/F4 gate logic and MTF closed-bar semantics verified. Mutation suite 7/7 detected by the full verifier. LIMITATIONS (unverified dimensions): numerical F2 zone boundary parity (narrow/wide/boundary-touch vs dedicated oracle), historical M30/H4 boundary-timestamp parity, and the full Candidate Setup population (694/686/594/92) were NOT re-derived in the Terminal environment (environmental/data-scope debt, §P, §X). ``` ## U. Production changes ```text NONE. All 13 frozen runtime source files verified byte-identical (normalized) to the authoritative repo before AND after this session. No compilation-error repair was performed. ``` ## V. ML changes ```text NONE. No MLP/weights/labels/features/FEATURE_CONTRACT modified. The ML path (AlgoForge_Backtest_Baseline, SniperGold_ML.mqh) was NOT executed. ``` ## W. External data changes ```text NONE. No Tickstory/Dukascopy/external CSV data introduced. The only data source was the terminal broker history via AFEngine1MTF. ``` ## X. Remaining verification debt ```text 1) Population-level Terminal replay (694/686 = 594 leads + 92 follow-ons) requires a historical semantic-input pipeline (F1 events + F2 zones + F4 states per M15 bar) feeding AFSetupEngine over the full research date range on a data source matched to the research environment. 2) Numerical F2 zone boundary tests (narrow/wide/boundary-touch, invalidation/consumption boundaries) against a dedicated Python zone oracle on identical bars. 3) Historical M30/H4 boundary-timestamp parity (exact MTF bar timestamps, missing-MTF-history, restart/reload behavior) vs an oracle. 4) Independent coefficient-level re-audit of P3-S21.1 (carried from P3-S21.R) — unchanged. ``` --- *End of P3-S22 verification document. Compiled PASS; terminal execution deterministic and non-trading; F3 contract EXACT; B — PASSED WITH LIMITATIONS; no production/ML/external-data change; P3-S23 NOT STARTED.*