SniperGold_ML/docs/SESSION_HANDOVER_2026-08-22_P3_S5_ORDER_BLOCK.md

13 KiB

SESSION HANDOVER — SNIPERGOLD_ML P3-S.5: ORDER BLOCK SPEC + CONFORMANCE

Date       : 2026-08-22 (session close)
Status     : P3-S.5 COMPLETE — spec + conformance audit done; synthetic tests 20/20;
             NOT yet committed (handover prepared before commit+push)
Forge      : https://forge.mql5.io/chiki2bum2/SniperGold_ML
Checkpoint : P3-S.4 176880f8f3f17afb7e922a48ed953daa22c1515f (VERIFIED clean at start)

1. SESSION OBJECTIVE

Formal Specification + Code-Conformance Audit for Order Block (OB).

Question answered:
  Does the SniperGold code claiming to detect Order Blocks really implement the
  OB definition established by the PROJECT SEMANTIC SPECIFICATION?

Questions NOT answered:
  - Does OB generate profit?
  - Does OB improve AUC / PF?
  - Is the universal SMC OB definition correct for every trader?

Principle: SPEC FIRST, CODE AUDIT SECOND. Human verification = CANCELLED. No production code changes (Phase D). No ML / AUC / PF / backtest optimization.


2. SOURCE MATERIAL (15 sources, reconciled)

 1 DESIGN.md (Algo Forge)                docs/DESIGN.md:132-133,206 (intent: OB =
                                         "opposite bar before a strong move")
 2 Engine 2 detector                     Include\AlgoForge\AF_Engine2_Agents.mqh:293-322
                                         (AF_FindOrderBlock)
 3 AF_AvgBody                            AF_Engine2_Agents.mqh:120-127
 4 Engine 2 C agent                      AF_Engine2_Agents.mqh:492-575 (weight 0.30)
 5 Engine 2 E agent                      AF_Engine2_Agents.mqh:583-663 (ZONE+CONFIRM)
 6 Engine 3 display collector            Include\AlgoForge\AF_Engine2_Display.mqh:199-250
                                         (AF_CollectOBs)
 7 AF_Defines.mqh                        AF_Defines.mqh:57,59,60 (OB 5/0.15 ATR/1.5)
 8 Engine 3 render/indicator             AF_Engine3_Render.mqh; AF_Engine3_Display.mq5
 9 v4.3/v4.4 indicator                   Indicators\Downloads\SniperGold_SMC_ProPlus_v4_3/4_4.mq5
                                         (LEGACY structure-break OB: ProcessStructure
                                         RecordOB, FindEntryOB, Sweep->CHoCH->OB)
10 v4.5 indicator                        SniperGold_SMC_ProPlus_v4_5.mq5 (chart OB
                                         identical; + MTF OB per-TF RecordOB_mtf)
11 FEATURE_CONTRACT                      docs/FEATURE_CONTRACT.md — NO OB feature
12 EA runtime                            Experts\AlgoForge_Backtest_Baseline.mq5 — NO OB
13 Python training                       ml/**/*.py — NO OB (0 refs)
14 P3 docs                               P3_2_2 / P3_2_LABEL_FORENSIC: "breaker" = FUTURE
                                         concept only
15 External                              SMC Order Block Detector.mq5 /
                                         XAUUSD_MTF_Liquidity_OB_Reversal (2).mq5:
                                         external references, NOT wired to the project

Three semantic layers separated:
  INTENDED : OB = opposite bar before a strong move (DESIGN.md); C agent context
             zone; E agent entry zone (ZONE + CONFIRMATION = setup); display
             zones with MIT filter + dedupe + min size 0.15xATR.
  LEGACY   : v4.3/v4.4/v4.5: OB = opposite candle BEFORE A STRUCTURE BREAK
             (BOS/CHoCH on swing len=50 / internal len=5); last or highest-volume
             opposite candle; full range; min 0.15xATR; close-through mitigation;
             internal + swing OBs; entry chain.
  CURRENT  : Algo Forge: opposite bar before strong move (1.5 x avg body); zone =
             full range; Engine 2 = newest-only, NO min size, NO mitigation;
             display = newest N unmitigated, 0.15xATR min, close-through mit,
             0.5xATR dedupe.
  TRAINING : N/A (no OB feature).  DISPLAY-ONLY: Engine 3 / v4.4 / v4.5 MTF OB.

3. SPECIFICATION (docs/SMC_ORDER_BLOCK_SPEC_v1.md)

FORMATION    : canonical current = opposite-color candle B immediately before
               strong-move candle M (|body(M)| >= 1.5 x avg body, avg over the
               last 20 closed bars). LEGACY second definition = opposite candle
               before a STRUCTURE BREAK (BOS/CHoCH) — recorded as A-2.
CANDLE       : B = full opposite candle (Close vs Open); doji excluded; zone =
               FULL RANGE [Low(B), High(B)].
BOUNDARIES   : top = High(B), bot = Low(B); no padding; min size none in the
               definition (0.15 ATR consumer filters, A-1).
DIRECTION    : +1 bullish (bearish B + bullish M), -1 bearish, 0 none;
               direction = move direction.
PRECONDITION : NONE (canonical); BOS/CHoCH/displacement/liquidity NOT required.
TIMING       : observable at M close (B+1 <= t); newest pair (t-1, t); NO 1-bar
               lag; timestamp = B open; closed-bar lock; no future.
LIFECYCLE    : ZONE + FORMATION EVENT; one zone per pair; no event stream;
               no age expiry; one zone stays ONE zone (T09).
MITIGATION   : close-through full fill (Close < Low(B) bull / > High(B) bear);
               partial/wick NOT mitigation.
INVALIDATION : NOT MODELED.
OVERLAP      : separate zones per pair; display dedupe 0.5 x ATR (A-3).
BREAKER      : NOT IMPLEMENTED (0 code matches; future concept only).
TIMEFRAME    : Engine 2 per-TF (H4/M30/M15/M3); canonical = AMBIGUOUS (A-4).
CONSUMERS    : C (context, w 0.30), E (entry zone), legacy entry gate
               (all-unmitigated within tap), display; NO ML feature.
PARITY       : PARITY = N/A BY ABSENCE (OB not in f0-f18 / EA / Python).

4. CONFORMANCE (docs/P3_S5_ORDER_BLOCK_CONFORMANCE.md)

Formation (E-1, E-2, E-4, E-6, E-7)      : CONFORMING (current definition)
Zone boundaries (E-3)                    : CONFORMING (+ AMBIGUOUS A-1 min size)
Structural precondition (E-5)            : CONFORMING (current = none);
                                           legacy BOS/CHoCH rule = A-2
Lifecycle (E-8)                          : CONFORMING (zone; no event duplication)
Mitigation (E-9)                         : NON-CONFORMING (Engine 2, BUG-P3S5-001)
Invalidation (E-10)                      : CONFORMING (not modeled)
Overlap (E-11)                           : PARTIALLY CONFORMING (A-3)
Breaker (E-12)                           : NOT IMPLEMENTED (no claim)
Timeframe (E-13)                         : SPECIFICATION AMBIGUOUS (A-4)
Consumer semantics (E-14)                : PARTIALLY CONFORMING (BUG-P3S5-001, A-5)
Runtime/training parity (E-15)           : CONFORMING (N/A by absence)

VERDICT : PARTIALLY CONFORMING
  (conformance to the project spec; NOT profitability/edge)

5. SYNTHETIC TESTS

Runner  : ml/p3/smc_semantic/spec_tests_order_block.py
Cases   : ml/p3/smc_semantic/spec_test_cases_order_block.json (20 cases)
Report  : ml/p3/smc_semantic/output/spec_tests_order_block_report.json

Result  : 20/20 PASS
  OB-T01..T20 (all required). spec_oracle (truth, from SPEC S-1..S-15) ==
  expected in all cases; symmetry property (S-4) asserted on EVERY case.
  code_port (Engine-2 AF_FindOrderBlock port, observation) MATCHES spec in
  T01-T05/T07-T10/T13-T15/T17-T19; DIVERGES in:
    T06/T11/T12/T16: spec newest-unmitigated = none (mitigated) vs code returns
             the zone -> synthetic evidence for BUG-P3S5-001.
  Expected derived from SPEC, NOT from production code.
  Parity scan (T20): FEATURE_CONTRACT.md = 0 order-block refs; ml/**/*.py = 0
  (excluding the spec test files) -> PARITY = N/A BY ABSENCE.
NO AUC/PF/backtest/human annotation/ML on the test path.

6. CONFIRMED BUGS (document-only; NOT fixed in P3-S.5)

BUG-P3S5-001 [MEDIUM] CONFIRMED, NOT FIXED
  Engine-2 AF_FindOrderBlock (AF_Engine2_Agents.mqh:293-322) has NO mitigation
  filter and NO age/freshness bound: the Context (weight 0.30) and Entry (zone
  tap) agents can consume a FULLY-FILLED OB as a current zone, and the newest OB
  can be hundreds of bars old. It also returns ONLY the newest zone (older
  unmitigated OBs invisible), diverging from the legacy entry rule
  (FindEntryOB: all unmitigated within tap). Same bug class as BUG-P3S4-001
  (FVG side). NOT the f7/f9/f18 duplication class — OB is a zone, not an event
  stream (verified OB-T09).
  Fix: apply the close-through mitigation filter (S-9) to AF_FindOrderBlock (or
  filter mitigated zones in the agents) and add a zone-age bound if freshness is
  required; document the zone-selection rule.

BUG-P3S5-002 [LOW] DOCUMENTED
  Two OB definitions in one project: Algo Forge "opposite bar before strong move
  (1.5 x avg body)" vs legacy v4.3/v4.4/v4.5 "opposite candle before STRUCTURE
  BREAK (BOS/CHoCH)" (+ legacy volume-weighted mode InpVolumeOB/InpOBStyle).
  The two rules can select DIFFERENT candles for the same price sequence.
  Fix: document the current rule as canonical; mark the legacy rule as historical.

BUG-P3S5-003 [INFO] DOCUMENTED
  Minimum zone size filters diverge: Engine-2 none / display 0.15 ATR / legacy
  0.15 ATR (A-1). No canonical value; not optimized here.

BUG-P3S5-004 [INFO] DOCUMENTED
  Display dedupe (0.5 x ATR) vs Engine-2 newest-only vs legacy keep-all (A-3):
  three zone-selection policies. Not adjudicated.

7. SEMANTIC AMBIGUITIES

1. Minimum zone size (A-1)     : none / 0.15 ATR / 0.15 ATR; no canonical value.
2. Two OB definitions (A-2)    : strong-move (current) vs structure-break (legacy).
3. Overlap / dedupe (A-3)      : display 0.5 ATR dedupe vs keep-all.
4. Canonical timeframe (A-4)   : Engine-2 M15 slot explicit; HTF OB as M15
                                 context / M3 execution not defined (same class as
                                 CHoCH G-4 / sweep G-3 / FVG A-3).
5. Consumer zone scope (A-5)   : Engine-2 newest-ANY (no mit/age) vs legacy
                                 all-unmitigated within tap.
6. Volume-weighted OB (A-6)    : legacy-only (InpVolumeOB / OB_HIGHEST_VOLUME);
                                 current = last candle only.

8. PREVIOUS BUG-CLASS CHECK (per brief §27)

The f7/CHoCH/FVG cross-layer pattern (detector correct -> zone/state correct ->
consumer incorrect) was explicitly checked for OB:

  detector     : AF_FindOrderBlock — correct for FORMATION (S-1..S-6)      OK
  zone/state   : zone list — correct (one zone per pair, no duplication)   OK
  consumer     : C/E agents consume the newest-ANY zone WITHOUT the
                 mitigation filter that display/legacy apply                FAIL

-> The cross-layer gap EXISTS for OB (BUG-P3S5-001: mitigation/age not applied
   by the Engine-2 detector/consumers). It is the SAME class as BUG-P3S4-001
   (FVG) — a mitigation-lifecycle gap, NOT the f7/f9/f18 stale-event
   duplication (proven: OB-T09 zone_count=1 after 19 bars).

9. NO PRODUCTION CHANGE

No production code was modified.
  AF_FindOrderBlock / AF_CollectOBs / v4.3 / v4.4 / v4.5 / Engine 2 / Engine 3 /
  f7 / f8 / f9 / f10 / f11 / f18 / FVG / CHoCH / Displacement / ML / EA :
  NOT touched.

Only P3-S.5 research artifacts added (spec, conformance, tests, report, handover).
P3-S.4 / P3-S.3 / P3-S.2 artifacts (immutable) UNCHANGED
(git status: only new files, 0 modified).

10. HUMAN VERIFICATION STATUS

HUMAN VERIFICATION = CANCELLED
  Human annotation is NOT part of the OB validation path.
  The human_package/ remains a historical artifact only.

11. NEXT GATE

After the Order Block verdict (PARTIALLY CONFORMING):
  Displacement -> MTF Alignment -> Candidate Setup.
DO NOT return to ML; DO NOT build a meta-label; DO NOT create new event labels;
DO NOT fix production bugs before the audit chain completes (BUG-P3S5-00x stay
documented until the semantic audit chain is finished).

12. CHECKPOINT & PROVENANCE (P3-S.5)

Forge HEAD (session start)   : 176880f (P3-S.4) — VERIFIED
P3-S.4 spec (immutable)      : docs/SMC_FVG_SPEC_v1.md
P3-S.3 spec (immutable)      : docs/SMC_CHOCH_MSS_SPEC_v1.md
P3-S.2 spec (immutable)      : docs/SMC_LIQUIDITY_SWEEP_SPEC_v1.md
FEATURE_CONTRACT             : C44CC6F2... (P2-era) / 7b908b12... (committed)
symbol/tf                    : XAUUSD / M15 (2017-01-01 .. 2026-08-20)
Human verification           : CANCELLED

13. P3-S.5 ARTIFACTS

docs/SMC_ORDER_BLOCK_SPEC_v1.md
docs/P3_S5_ORDER_BLOCK_CONFORMANCE.md
ml/p3/smc_semantic/spec_tests_order_block.py
ml/p3/smc_semantic/spec_test_cases_order_block.json
ml/p3/smc_semantic/output/spec_tests_order_block_report.json
docs/SESSION_HANDOVER_2026-08-22_P3_S5_ORDER_BLOCK.md  (this document)

14. COMMIT & PUSH STATUS

NOT YET COMMITTED at handover write time.
Planned commit message:
  research: P3-S.5 Order Block formal spec + conformance audit (PARTIALLY CONFORMING)
Follow with: git push origin main; verify rev-parse HEAD == ls-remote origin HEAD;
working tree CLEAN.