From 7e82b2ce5a2c49bfced547a1578a4c816621b85e Mon Sep 17 00:00:00 2001 From: mo Date: Tue, 25 Aug 2026 10:10:27 -0400 Subject: [PATCH] [GAP-059]: ORB range telemetry context complete - SimpleORBNT8.cs: source telemetry ORB range from SDK opening range tracker - SimpleORBNT8DefaultsTests.cs: guard against dead adapter ORB fields and verify SDK source - OrbConfluenceFactorTests.cs: prove realistic ORB range ticks produce ratio reason - SPRINT_BOARD.md and decisions.md: record implementation and deploy blocker Build: clean | Tests: 545 passing; Core 456 passing | Dual-deployed: no - NinjaTrader.exe PID 18800 locked NT8.Core.dll --- SPRINT_BOARD.md | 4 + TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md | 137 ++++++++++++++++++ docs/00-governance/decisions.md | 10 ++ src/NT8.Adapters/Strategies/SimpleORBNT8.cs | 7 +- .../Adapters/SimpleORBNT8DefaultsTests.cs | 14 ++ .../Intelligence/OrbConfluenceFactorTests.cs | 22 +++ 6 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md diff --git a/SPRINT_BOARD.md b/SPRINT_BOARD.md index e85a811..aee6dbf 100644 --- a/SPRINT_BOARD.md +++ b/SPRINT_BOARD.md @@ -69,6 +69,10 @@ - Live SIM spot-check 2026-08-23/24: file log shows a ~16-hour `REJECT SUMMARY` blackout (`23:55:01` Aug 23 night → `16:00:00` Aug 24 afternoon), covering the entire 09:30-16:00 ET trading day. Confirmed the 09:30-10:00 "Grade A" telemetry Mo saw is by-design (real order path correctly blocked pre-ORB-close; those are hypothetical default-long diagnostic scores, not real signals) — but the log currently cannot show *why* any bar was rejected for that whole span. - Root cause: `MaybeWriteRejectSummarySnapshot`'s blanket `TimeOfDay < 10:00 AM` gate suppresses the entire midnight-10am span daily (not just the ORB window); `_orbRejectSummarySnapshotWritten` is a session-lifetime flag that fires once (here, accidentally, during the first night's ETH activity) and never again on a multi-day run; snapshots are only ever reject-triggered with no independent timer. - Prompt: `TASK_GAP060_REJECT_SUMMARY_VISIBILITY_PROMPT.md`. Implemented as observability-only: suppression is now ORB-window/date-aware, the once-after-ORB flag resets per day, and `OnBarUpdate` checks summary cadence on the live bar heartbeat instead of only inside reject logging. Open question resolved as (a): `SimpleORBStrategy.OnBar()` does record `OrbRangeNotEstablished` before and after ORB close during an RTH no-breakout path; missing visibility was adapter summary reporting, not a distinct SimpleORB defect. Verification: focused tests 8/8, `verify-build.bat` 543/543, Core Release no-build 454/454. Deployment attempted but blocked because NinjaTrader.exe PID 18800 locked `NT8.Core.dll`; commit made per operator instruction without deploy. +**[GAP-059] Telemetry `OrbRangeVsAtr` always reports "no daily bar context"** | Stage 1 | ✅ IMPLEMENTED — deploy blocked by running NT8 +- `SimpleORBNT8.OnBarUpdate()` computed `orbRangeTicks` from `_openingRangeHigh`/`_openingRangeLow`, two fields declared but never assigned anywhere in the file — permanently `0.0`. GAP-049's telemetry fix depended on this value being nonzero and never fired as a result. +- Correct live values already existed in the same file (`sdkOrb.OpeningRangeHigh`/`OpeningRangeLow`, used correctly at the `STATE_CONTEXT` and diagnostics call sites) — this was a wiring fix, not new logic. Confirmed data-source only; no order flow, sizing, or risk behavior changed. +- Prompt: `TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md`. Implemented by sourcing the adapter-built daily context's ORB range from `SdkSimpleORB.OpeningRangeHigh/OpeningRangeLow` only when `OpeningRangeReady` is true, then removing the dead adapter fields. This lets GAP-049's telemetry clone emit nonzero `orb_range_ticks` and gives `OrbRangeVsAtrFactorCalculator` the context it already expected. Verification: focused tests 32/32, `verify-build.bat` 545/545, Core Release no-build 456/456. Deployment blocked because NinjaTrader.exe PID 18800 locked `NT8.Core.dll`; commit made per operator instruction without deploy. ### Also raised by the review, not yet prompted GAP-051 (`MicroUpgradeThreshold` fires every session) · GAP-052 (two hardcoded tick-value tables) · GAP-053 (`executive_summary.md` and `roadmap.md` Sprint 3 list present ~12 completed tasks as open) · diff --git a/TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md b/TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md new file mode 100644 index 0000000..6f02f97 --- /dev/null +++ b/TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md @@ -0,0 +1,137 @@ +# TASK: GAP-059 — Telemetry OrbRangeVsAtr always reports "no daily bar context" +# Staged: 2026-08-23/24 (found during live post-compile SIM validation of GAP-049) +# Sprint: Stage 1 — housekeeping, zero trading-behaviour risk (observability only) +# Owner: Kilocode +# ───────────────────────────────────────────────────────────────── + +## THE DEFECT + +`OrbRangeVsAtrFactorCalculator.Calculate()` (`FactorCalculators.cs` ~612-622) +requires `intent.Metadata["orb_range_ticks"]` to be present; otherwise it +returns the neutral fallback and the reason string +"No daily bar context available". + +GAP-049 (this session, commit `a005dee`) added the code that's supposed to +supply that key for `STATE:` telemetry: + + metadata.Add("daily_bars", telemetryDaily); + if (telemetryDaily.OrbRangeTicks > 0.0) + metadata.Add("orb_range_ticks", telemetryDaily.OrbRangeTicks); + +`telemetryDaily.OrbRangeTicks` is a straight copy of whatever +`_strategyConfig.Parameters["daily_bars"].OrbRangeTicks` already held. That +source is rebuilt every bar in `SimpleORBNT8.OnBarUpdate()` (~168-183): + + double orbHigh = _openingRangeHigh; + double orbLow = _openingRangeLow; + double orbRangeTicks = 0.0; + if (orbHigh > orbLow) { ... } + DailyBarContext dailyContext = BuildDailyBarContext(_lastSignalDirection, orbRangeTicks, (double)Volume[0]); + _strategyConfig.Parameters["daily_bars"] = dailyContext; + +`_openingRangeHigh` and `_openingRangeLow` (declared ~108-109) are **declared +and read but never assigned anywhere in this file.** They are permanently +`0.0`, so `orbHigh > orbLow` is always false, `orbRangeTicks` is always +`0.0`, and GAP-049's `> 0.0` guard never passes. The telemetry fix itself is +correct — the value it depends on has been dead since before this session. + +## RUNTIME PROOF — live SIM, 2026-08-23/24 + +`session_20260823_230519.log`, every `STATE_DETAIL` line from 08:29 ET +through at least 10:49 ET (i.e. well past the 09:30-10:00 ORB window): + + OrbRangeVsAtr="No daily bar context available" + +while the same lines' `STATE_CONTEXT` confirms the real opening range is +fully formed: + + STATE_CONTEXT: OrbHigh=29243.00 OrbLow=28946.75 OrbWindowStart=09:30 OrbWindowEnd=10:00 OrbReady=True + +## WHERE THE CORRECT VALUE ALREADY LIVES + +`SimpleORBNT8.cs` already reads the real, live opening range correctly in +three other places in the same file, all from the SDK-side ORB tracker: + + sdkOrb.OpeningRangeHigh / sdkOrb.OpeningRangeLow / sdkOrb.OpeningRangeReady + +- ~355-360: builds `STATE_CONTEXT: OrbHigh=/OrbLow=` from these fields + (confirmed this is what the live log's correct OrbHigh/OrbLow come from). +- ~565-569: an existing, separate `orbRangeTicks` computation already uses + exactly this pattern: `Math.Round((sdkOrb.OpeningRangeHigh - + sdkOrb.OpeningRangeLow) / tickSize)`. + +`_openingRangeHigh`/`_openingRangeLow` appear to be superseded/legacy fields +that were never finished being wired up (or never removed after the SDK-side +tracker took over). Confirm this reading is correct before changing +anything — search the whole file and its base class for any other writer of +these two fields that a plain grep might have missed. + +## SCOPE — confirm, do not assume + +`_strategyConfig.Parameters["daily_bars"]` is read in exactly one place in +`SimpleORBNT8.cs`: the telemetry-building code GAP-049 added +(`BuildStateTelemetryIntent`). Real trade-signal scoring appears to get its +daily/ORB context a different way (inside `SimpleORBStrategy`/ +`AttachDailyBarContext()`), not through this dead-field path — meaning this +defect is very likely telemetry-only and does not affect real signal +grading, sizing, risk, or order submission. **Verify this by reading the +actual call sites rather than trusting this summary** — if real trade +scoring does share this broken path, that changes this task's priority +significantly and should be reported back before proceeding with the +telemetry-only fix below. + +## THE CHANGE + +In `SimpleORBNT8.OnBarUpdate()` (~168-183), replace the `orbHigh`/`orbLow` +source with the SDK-side tracker, matching the existing pattern at ~565-569: + + SdkSimpleORB sdkOrb = _sdkStrategy as SdkSimpleORB; + double orbHigh = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeHigh : 0.0; + double orbLow = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeLow : 0.0; + +(Adjust to match whatever null/readiness guard style the ~355-360/~565-569 +call sites already use — reuse their exact pattern rather than inventing a +new one.) + +Once confirmed genuinely dead (no other writer found anywhere), remove the +`_openingRangeHigh`/`_openingRangeLow` fields entirely in the same change — +don't leave unused fields that look like they matter. + +## DO NOT + +- Do not change `OrbRangeVsAtrFactorCalculator`'s scoring logic — it is + correct; it just isn't receiving data. +- Do not change GAP-049's `CloneDailyBarContextForTelemetry` logic — its + `> 0.0` guard is correct once the upstream value is real. +- Do not touch real trade-signal generation, sizing, risk, or order + submission — this is a telemetry data-source fix only, unless the Scope + check above finds otherwise, in which case stop and report back first. + +## TESTS (required) + +1. A test proving `SimpleORBNT8.OnBarUpdate()` (or whatever seam exists) + populates `orb_range_ticks` metadata with a nonzero value once + `sdkOrb.OpeningRangeReady` is true and `OpeningRangeHigh > OpeningRangeLow` + — mirroring the pattern already used for GAP-049's other tests in + `SimpleORBNT8DefaultsTests.cs` if no execution seam exists (source-text + assertion is acceptable here for the same NinjaScript-instantiation + reason as GAP-049, but say so explicitly rather than silently reusing the + pattern without noting the limitation). +2. A test proving `OrbRangeVsAtrFactorCalculator` returns a non-neutral, + non-"no context" result when fed a `daily_bars`/`orb_range_ticks` pair + built from realistic ORB high/low values (can likely extend or mirror the + existing `OrbConfluenceFactorTests.cs` patterns from GAP-049). + +## VALIDATION (operator) + +Live/SIM only, after manual NT8 compile. Confirm a `STATE_DETAIL` line taken +after `OrbReady=True` in `STATE_CONTEXT` no longer reads +`OrbRangeVsAtr="No daily bar context available"` and instead reports a real +ratio-based reason. + +## GOVERNANCE + +Track as [GAP-059] in SPRINT_BOARD.md. Update `docs/00-governance/decisions.md` +DEC-20260823-05 status to `implemented` with an implementation note on +completion. +Reference: this task, DEC-20260823-05, `session_20260823_230519.log`. diff --git a/docs/00-governance/decisions.md b/docs/00-governance/decisions.md index 210084e..9617315 100644 --- a/docs/00-governance/decisions.md +++ b/docs/00-governance/decisions.md @@ -24,6 +24,16 @@ Use this file to record durable project decisions that affect implementation pat - **Related Files:** `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` (`MaybeWriteRejectSummarySnapshot`/`LogRejectRateLimited`/`ResetRejectTracking`/`WriteSessionHeader` ~1444-1517), `src/NT8.Strategies/Examples/SimpleORBStrategy.cs` (`OnBar` ~355-432, `RecordSignalRejection` ~1015-1026), `session_20260823_230519.log` - **Implementation Note (2026-08-25):** GAP-060 implemented as logging/observability only. `NT8StrategyBase.MaybeWriteRejectSummarySnapshot()` no longer has a blanket midnight-to-10:00 AM suppression gate; suppression now delegates to an ORB-window-aware helper and `SimpleORBNT8` overrides that helper so the suppressed window is today's configured 09:30 + `OpeningRangeMinutes`. The once-after-ORB snapshot flag now resets per `barTime.Date`, allowing a new post-ORB summary every day in a continuous multi-day session. `OnBarUpdate()` now calls `MaybeWriteRejectSummarySnapshot(Time[0])` on the live bar heartbeat after the first realtime-bar guard, so 15-minute summary cadence can flush from regular processed bars and is not solely dependent on a newly logged reject. Existing `_rejectDetailsLogged` one-detail-line-per-reason rate limiting, reject reason strings, `REJECT:`/`REJECT SUMMARY:` formats, order flow, sizing, risk, and real trade decisions were unchanged. Open question resolved as possibility **(a)**: the missing `OrbRangeNotEstablished` visibility was adapter summary reporting, not a second SimpleORB rejection defect. A focused `SimpleORBStrategy.OnBar()` test proves the no-breakout RTH path records `OrbRangeNotEstablished` both while the ORB is building and after ORB close when no breakout confirms. Verification: focused GAP-060 tests passed 8/8; `verify-build.bat` passed with 543/543 tests (454 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 454/454. - **Action Required:** Deployment remains pending. `deployment\deploy-to-nt8.bat` was attempted on 2026-08-25 but failed because NinjaTrader.exe PID 18800 locked `NT8.Core.dll`; operator instructed Kilocode to commit without deploy. After NinjaTrader is closed, rerun deployment, start NT8, manually compile NinjaScript, and in the next SIM session spanning a full trading day confirm `REJECT SUMMARY` appears throughout RTH at a reasonable cadence. +### DEC-20260823-05 +- **ID:** DEC-20260823-05 +- **Date:** 2026-08-23/24 (live SIM session spanning midnight) +- **Status:** implemented +- **Context:** Continuing tonight's post-compile SIM validation (`session_20260823_230519.log`), `STATE_DETAIL` lines from 08:29 ET through 10:49 ET (well past the 09:30-10:00 ORB window, with `STATE_CONTEXT` confirming `OrbReady=True OrbHigh=29243.00 OrbLow=28946.75`) all still report `OrbRangeVsAtr="No daily bar context available"` — the exact second symptom GAP-049's task description originally flagged, and which DEC-20260823-03's Action Required specifically asked to be re-checked live. `GapDirectionAlignment` is confirmed working correctly in the same lines (e.g. `Large gap -278.25 aligns with trade`), so this is not a re-occurrence of the direction bug — it's a distinct, still-open issue. +- **Root cause:** `OrbRangeVsAtrFactorCalculator.Calculate()` requires `intent.Metadata["orb_range_ticks"]` to be present. GAP-049's fix correctly adds that key when `telemetryDaily.OrbRangeTicks > 0.0`, but `telemetryDaily.OrbRangeTicks` copied the adapter-built `_strategyConfig.Parameters["daily_bars"].OrbRangeTicks`. That source was built in `SimpleORBNT8.OnBarUpdate()` from local fields `_openingRangeHigh`/`_openingRangeLow`, which were declared/read but never assigned, so the ORB range stayed `0.0` and telemetry never emitted `orb_range_ticks`. +- **Decision:** Track as **GAP-059** and fix the adapter daily-context data source only. Source `orbHigh`/`orbLow` from `(_sdkStrategy as SdkSimpleORB).OpeningRangeHigh`/`OpeningRangeLow` when `OpeningRangeReady` is true, matching the existing `STATE_CONTEXT` and diagnostics source of truth, and remove the dead legacy fields. +- **Implementation Note (2026-08-25):** GAP-059 implemented in `SimpleORBNT8.OnBarUpdate()` by reading `SdkSimpleORB sdkOrb = _sdkStrategy as SdkSimpleORB` and using `sdkOrb.OpeningRangeHigh` / `sdkOrb.OpeningRangeLow` only when `sdkOrb.OpeningRangeReady` is true. The unused `_openingRangeHigh` and `_openingRangeLow` adapter fields were removed after search confirmed no writer existed. `OrbRangeVsAtrFactorCalculator`, GAP-049's telemetry clone, signal generation, sizing, risk, order submission, and line formats were unchanged. Scope nuance: the SDK strategy does read `_config.Parameters["daily_bars"]` for daily context, but real ORB-range metadata is still set from `SimpleORBStrategy.CreateIntent()`/`AttachDailyBarContext()` once a real candidate exists; this fix corrects the adapter's stale daily-context source feeding telemetry and shared daily context. +- **Evidence:** Added source-level `SimpleORBNT8DefaultsTests` coverage because NinjaScript strategies are not directly instantiated in normal Core tests; added `OrbConfluenceFactorTests` coverage proving realistic SDK ORB high/low-derived ticks produce a ratio-based `OrbRangeVsAtr` reason instead of the neutral missing-context reason. Focused GAP-059 tests passed 32/32. `verify-build.bat` passed with 545/545 tests (456 Core, 79 Integration, 10 Performance). `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 456/456. +- **Action Required:** Deployment remains pending. `deployment\deploy-to-nt8.bat` was not rerun because NinjaTrader.exe PID 18800 remained active and previously locked `NT8.Core.dll`; operator instructed Kilocode to commit without deploy. After NinjaTrader is closed, rerun deployment, start NT8, manually compile NinjaScript, and confirm a post-`OrbReady=True` `STATE_DETAIL` line reports a ratio-based `OrbRangeVsAtr` reason instead of `No daily bar context available`. ### DEC-20260823-03 - **ID:** DEC-20260823-03 - **Date:** 2026-08-23 diff --git a/src/NT8.Adapters/Strategies/SimpleORBNT8.cs b/src/NT8.Adapters/Strategies/SimpleORBNT8.cs index 92eb3c5..affca77 100644 --- a/src/NT8.Adapters/Strategies/SimpleORBNT8.cs +++ b/src/NT8.Adapters/Strategies/SimpleORBNT8.cs @@ -105,8 +105,6 @@ namespace NinjaTrader.NinjaScript.Strategies public int TargetTicks { get; set; } // ORB internal state for diagnostics - private double _openingRangeHigh; - private double _openingRangeLow; private bool _openingRangeReady; private bool _breakoutBarSeen; private int _pendingBreakoutDirection; @@ -169,8 +167,9 @@ namespace NinjaTrader.NinjaScript.Strategies { if (_strategyConfig != null && BarsArray != null && BarsArray.Length > 1) { - double orbHigh = _openingRangeHigh; - double orbLow = _openingRangeLow; + SdkSimpleORB sdkOrb = _sdkStrategy as SdkSimpleORB; + double orbHigh = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeHigh : 0.0; + double orbLow = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeLow : 0.0; double orbRangeTicks = 0.0; if (orbHigh > orbLow) { diff --git a/tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs b/tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs index fbf5e26..d738083 100644 --- a/tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs +++ b/tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs @@ -43,6 +43,20 @@ namespace NT8.Core.Tests.Adapters Assert.IsTrue(method.Contains("daily.BreakoutBarVolume = (double)barData.Volume;"), "Telemetry clone must use current bar volume for breakout-volume scoring."); } + [TestMethod] + public void OnBarUpdate_DailyContextOrbRange_UsesSdkOpeningRangeTracker() + { + string source = File.ReadAllText(FindSourceFile()); + string method = ExtractMethodBlock(source, "protected override void OnBarUpdate"); + + Assert.IsTrue(method.Contains("SdkSimpleORB sdkOrb = _sdkStrategy as SdkSimpleORB;"), "Daily context must read the live SDK-side ORB tracker."); + Assert.IsTrue(method.Contains("double orbHigh = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeHigh : 0.0;"), "Daily context must use SDK ORB high only after the range is ready."); + Assert.IsTrue(method.Contains("double orbLow = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeLow : 0.0;"), "Daily context must use SDK ORB low only after the range is ready."); + Assert.IsTrue(method.Contains("orbRangeTicks = Math.Round((orbHigh - orbLow) / tickSize);"), "Daily context must compute ORB range ticks from SDK high/low."); + Assert.IsFalse(source.Contains("_openingRangeHigh"), "Legacy adapter ORB high field must stay removed because the SDK tracker owns this state."); + Assert.IsFalse(source.Contains("_openingRangeLow"), "Legacy adapter ORB low field must stay removed because the SDK tracker owns this state."); + } + private static string FindSourceFile() { DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); diff --git a/tests/NT8.Core.Tests/Intelligence/OrbConfluenceFactorTests.cs b/tests/NT8.Core.Tests/Intelligence/OrbConfluenceFactorTests.cs index edd6743..7615077 100644 --- a/tests/NT8.Core.Tests/Intelligence/OrbConfluenceFactorTests.cs +++ b/tests/NT8.Core.Tests/Intelligence/OrbConfluenceFactorTests.cs @@ -97,6 +97,28 @@ namespace NT8.Core.Tests.Intelligence Assert.IsTrue(result.Score <= 0.15); } + [TestMethod] + public void OrbRangeVsAtr_RealisticSdkOrbRangeTicks_ReturnsRatioReason() + { + var calc = new OrbRangeVsAtrFactorCalculator(new BasicLogger("test")); + var intent = CreateIntent(); + var daily = CreateDailyContext(new double[] { 290, 310, 280, 300, 305, 295, 300 }); + double sdkOrbHigh = 29243.00; + double sdkOrbLow = 28946.75; + double tickSize = 0.25; + double orbRangeTicks = Math.Round((sdkOrbHigh - sdkOrbLow) / tickSize); + + daily.OrbRangeTicks = orbRangeTicks; + intent.Metadata["daily_bars"] = daily; + intent.Metadata["orb_range_ticks"] = daily.OrbRangeTicks; + + var result = calc.Calculate(intent, CreateContext(), CreateBar()); + + Assert.AreNotEqual(0.5, result.Score, 0.000001); + Assert.IsFalse(result.Reason.Contains("No daily bar context available"), result.Reason); + Assert.IsTrue(result.Reason.Contains("ORB is"), result.Reason); + } + [TestMethod] public void OrbRangeVsAtr_MissingContext_DefaultsTo05() {