SniperGold_ML/docs/P2_3_CONTEXT_WINDOW.md

3.3 KiB

P2.3 — RUNTIME CONTEXT WINDOW (minimum history requirement)

Status: RESOLVED — verified 0/0/0/0 mismatch (14850 rows)
Date: 2026-08-21
Source of truth: runtime deployment window = 700-bar M15 cache
(A 600-bar LOOKBACK alone is technically insufficient — see §3)


1. Runtime facts (from EA code + verification)

M15 cache  : maxBars = max(InpMaxBars=700, 2*SWING_LEN + LOOKBACK) = 700
             (the tester pre-loads 1 year -> cache full from the first row)
ProcessStructure : begin = max(startBar, 2*len) = max(100, 700-600) = 100
             loop i in [100, total)  -> 600 bars ANALYZED (cache bars 0..99 = warmup)
swing pivot: valid absolute p in [r-649, r-50]   (rel [50, 649])
             (IsPivotHigh needs neighbors p±50 inside the 700-bar cache)
g_swHigh   : price of the LAST swing HIGH pivot in that window; 0 if none
g_swLow    : analogous

2. Quantitative evidence (ml/parity/verify_window.py)

f6_eqpos  : mismatch = 0/14850  max|d| = 0.000000
f14_dhigh : mismatch = 0/14850
f15_dlow  : mismatch = 0/14850
f17_range : mismatch = 0/14850

The windowed reconstruction (sw_high/sw_low from [r-649, r-50], 0 when empty) reproduces the EA 100% for all four window-sensitive features.


3. Minimum history requirement per feature

Feature ID Minimum lookback Warm-up State dependency Runtime window
f0/f1/f2 (HTF bias) 200 newest HTF bars need<120 -> 0 none (200-bar window) HTF cache 250, corrected: 200 newest ending at E_ea
f3/f4/f5 (trend/bias) 600 bars of structure analyzed begin=100 (cache idx) pivot feed from [r-649, r-50] M15 cache 700
f6 eq_pos last swing pivot in [r-649, r-50] no pivot -> 0 sw_high/sw_low M15 cache 700
f7/f8/f9 (sweep/choch) 600 bars of internal structure begin=100 swing timeline M15 cache 700
f10/f11 (EQH/EQL) pairs in [r-649, r-50] pair < EQ_BARS skip swing pivot list M15 cache 700
f12/f13 (delta) 10 bars (DELTA_BARS) kk<=0 -> 0 none 10 bars
f14/f15 (dist) sw_high/sw_low + ATR(14) sw=0 -> 0 structure M15 cache 700
f16 (mom20) 21 bars (close[tc-21]) tc<21 -> 0 none 21 bars
f17 (range) sw_high/sw_low rng=0 -> 0 structure M15 cache 700
f18 (conf) derived (f0-f2,f5,f6,f7,f8) follows the above
ATR 14 bars i>=13 none 14 bars

Technical finding: a LOOKBACK of 600 alone is NOT sufficient — pivots at rel [50,99] (absolute [r-649, r-600]) also determine sw_high/sw_low and the EQH/EQL pairs, and their confirmation uses cache bars 0..99 (warmup). The minimum requirement for full parity = 700-bar cache (600 analyzed + 100 warmup).


4. Decision

Minimum required : 700 M15 bars (cache) — 600 analysis bars + 100 warmup;
                   HTF: 250-bar cache, 200 used (P2.1 corrected)
Production window: cache 700 / HTF 250 (runtime deployment window = SOURCE OF TRUTH)
Training window  : must replicate the 700-bar cache ending at the row bar (begin=100),
                   HTF 200 newest ending at E_ea — implemented in P2.5
Parity           : f6/f14/f15/f17 = 0/14850 (windowed reconstruction)

Note: the window was NOT chosen based on AUC. The runtime deployment window is the contract; if training needs a different window, that is outside P2 (recorded as a future experiment).