[GAP-061]: AVWAP state context telemetry complete

- SimpleORBNT8.cs: append Avwap, AvwapSlope, and TrendConfirm to STATE_CONTEXT when CustomData contains them

- SimpleORBNT8DefaultsTests.cs: add source assertions for AVWAP telemetry formatting, missing-key omission, and no scoring/log-format changes

- SPRINT_BOARD.md/decisions.md: record observability-only implementation and direction-blind trend_confirm finding

Build: clean | Tests: 561 passing; Core 472 passing | Dual-deployed: no - skipped by prompt
This commit is contained in:
2026-08-25 16:24:53 -04:00
parent 0607d44388
commit a673475738
5 changed files with 212 additions and 0 deletions

View File

@@ -87,6 +87,10 @@
**[GAP-057] No test seam for NinjaScript's SetStopLoss/SetTrailStop managed-order calls** | Stage 1 | ✅ IMPLEMENTED — test-only, deploy skipped by prompt
- Found during GAP-054 verification (`DEC-20260821-01`): the regression test GAP-054's own task asked for (no `SetStopLoss` after `SetTrailStop` for a runner signal) was never written because no test seam exists — Kilocode correctly declined to fabricate coverage rather than write a fake test. Same defect class as GAP-054 (silent exit-order clobbering) currently has zero regression protection.
- Prompt: `TASK_GAP057_STOP_TRAIL_TEST_SEAM_PROMPT.md`. Implemented Option B: source-text regression seam. Added tests proving the runner entry block never calls `SetStopLoss(_runnerSignalName...)` after `SetTrailStop(_runnerSignalName...)`, the post-entry runner monitor in `OnBarUpdate()` contains no `SetStopLoss`/`SetTrailStop` calls, and no production order-management indirection was introduced. Verification: focused tests 3/3, `verify-build.bat` 558/558, Core Release no-build 469/469. Deploy intentionally skipped by task prompt.
**[GAP-061] Expose raw AVWAP/slope/trend-confirm inputs in STATE_CONTEXT telemetry** | Stage 1 | ✅ IMPLEMENTED — deploy skipped by prompt
- Found during the "zero trades this week" investigation (`DEC-20260825-04`): every real breakout this week and on 2026-08-18 capped at Grade B/C, driven by `Trend=0.30` on every best short setup. Source read confirmed the sharper asymmetry: `trend_confirm` is `avwapSlope > 0.0 ? 1.0 : 0.0`, while short-side slope alignment requires `avwapSlope < 0.0`, so a short cannot earn both bonuses.
- Prompt: `TASK_GAP061_AVWAP_TELEMETRY_PROMPT.md`. Implemented as observability-only: `STATE_CONTEXT` now includes `Avwap` (`F2`), `AvwapSlope` (`F4`), and `TrendConfirm` (`F1`) when those existing `context.CustomData` keys are present. Missing keys are omitted with no placeholders. No scoring, `trend_confirm`, `STATE:`, `STATE_DETAIL:`, risk, sizing, or order-flow logic changed. Verification: focused tests 7/7, `verify-build.bat` 561/561, Core Release no-build 472/472. Deploy intentionally skipped by task prompt.
### 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) ·

View File

@@ -0,0 +1,136 @@
# TASK: GAP-061 — expose raw AVWAP/slope/trend-confirm inputs in STATE_CONTEXT telemetry
# Staged: 2026-08-25 (trade-frequency investigation, DEC-20260825-04)
# Sprint: Stage 1 — observability only, zero trading-behaviour risk
# Owner: Kilocode
# Deploy: COMMIT ONLY — do NOT run deploy-to-nt8.bat or copy build output to
# the live NT8 install as part of this task. Verify-build and commit
# as usual; leave the deploy step for the operator to run manually
# once ready.
# ─────────────────────────────────────────────────────────────────
## THE DEFECT (why this is worth doing)
Investigating "zero trades this week" (`DEC-20260825-04`) found that every
real, pullback-confirmed breakout this week and on 2026-08-18 (the only two
days with usable `STATE:` telemetry) capped out at Grade B or C — never A.
On both days, the common driver was `Trend=0.30` on the best real setups,
both `Direction=Sell`.
Reading `TrendAlignmentFactorCalculator.Calculate()`
(`src/NT8.Core/Intelligence/FactorCalculators.cs` ~116-186), the Trend
factor is additive: `+0.4` if price is on the trade's side of AVWAP, `+0.3`
if AVWAP slope agrees with direction, `+0.3` if `trend_confirm > 0.5`.
**Found something sharper than a hypothesis while tracing this — a
provable, direction-blind asymmetry, not something that needs new
instrumentation to confirm:** `trend_confirm` is set in
`SimpleORBStrategy.UpdateConfluenceInputs()`
(`src/NT8.Strategies/Examples/SimpleORBStrategy.cs:970`) as
`context.CustomData["trend_confirm"] = avwapSlope > 0.0 ? 1.0 : 0.0;` —
unconditionally rewarding a **positive** slope, regardless of trade
direction. For a Sell/short trade, `slopeAligned` (the `+0.3` above)
requires `avwapSlope < 0.0`. These two conditions are mutually exclusive by
construction: **a short trade can never earn both the `+0.3` slope-aligned
bonus and the `+0.3` trend-confirm bonus, even when the trend is cleanly
and correctly bearish.** The maximum a short trade with a genuinely
confirmed downtrend can score on this factor is `0.3` (or `0.7` if price
also happens to be below AVWAP) — never higher. This matches both real
days' data exactly: `Trend=0.30` on every best short setup.
This task is scoped to **observability only** — do not change
`trend_confirm`'s calculation or the Trend factor's logic here. The
purpose is to make the `avwap`/`avwap_slope`/`trend_confirm` raw values
visible in the log directly (same value class as GAP-059's
`orb_range_ticks` fix), so the price-vs-AVWAP question (the one part of
this that genuinely isn't provable from source alone — whether an ORB
breakout's early timing structurally prevents earning the `+0.4`
price-aligned bonus) can be checked against real numbers instead of
inferred, and so the `trend_confirm` asymmetry above is independently
visible in the log evidence too, not just in source. Whether to fix
`trend_confirm`'s direction-blindness is a separate decision — flag it in
your writeback but do not implement a fix in this task.
## READ-FIRST
1. `DEC-20260825-04` in `docs/00-governance/decisions.md` — the full
investigation this task follows from.
2. `src/NT8.Core/Intelligence/FactorCalculators.cs` ~116-186 —
`TrendAlignmentFactorCalculator`, confirm the additive logic described
above is still accurate.
3. `src/NT8.Strategies/Examples/SimpleORBStrategy.cs` ~926-975 —
`UpdateConfluenceInputs()`, where `avwap`/`avwap_slope`/`trend_confirm`
are computed and written to `context.CustomData` every bar.
4. `src/NT8.Adapters/Strategies/SimpleORBNT8.cs` ~356-370 —
`GetStateTelemetryContextFields()` override, where `STATE_CONTEXT`
fields are currently assembled (`OrbHigh`/`OrbLow`/`OrbWindowStart`/
`OrbWindowEnd`/`OrbReady`). This is where the new fields belong — same
pattern, same method.
5. `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` ~1038-1100
(`MaybeWriteStateTelemetry`) and ~1130 (the virtual base method) for
how `GetStateTelemetryContextFields`'s return value flows into the
`STATE_CONTEXT:` log line — read-only context, no changes needed here.
## THE CHANGE
In `SimpleORBNT8.GetStateTelemetryContextFields()`, add three fields read
from `context.CustomData` (same defensive pattern already used elsewhere
in this codebase for optional `CustomData` keys — null/missing-key safe,
never throws):
- `Avwap` — the raw `avwap` value (`F2`), if present.
- `AvwapSlope` — the raw `avwap_slope` value (`F4` — this is a small
number, don't round it away), if present.
- `TrendConfirm` — the raw `trend_confirm` value (`F1` is fine, it's
currently always `0.0` or `1.0`), if present.
Omit a field entirely (don't print a placeholder) when its key isn't in
`context.CustomData` yet, consistent with how `OrbHigh`/etc. are only
added once `OpeningRangeReady`. Do not change `UpdateConfluenceInputs()`,
`TrendAlignmentFactorCalculator`, or any other scoring logic — this task
only surfaces existing values that are already being computed every bar,
it does not compute anything new.
## DO NOT
- Do not change `trend_confirm`'s calculation, the Trend factor's
additive logic, or any other confluence-scoring code. That is a
separate decision (see THE DEFECT) and explicitly out of scope here.
- Do not change `MinTradeGrade`, `GradeFilter`, or any risk/order-flow
code.
- Do not change the `STATE:` or `STATE_DETAIL:` line formats — only
`STATE_CONTEXT:`.
## TESTS (required)
1. A test proving `GetStateTelemetryContextFields()` includes `Avwap`/
`AvwapSlope`/`TrendConfirm` when `context.CustomData` has those keys,
with correct formatting.
2. A test proving the method still returns `null` (or omits the new
fields) when `context.CustomData` lacks them, matching the existing
`OpeningRangeReady` guard behavior — no exceptions, no placeholder
values.
3. Confirm the full existing suite still passes, including whatever
covers `STATE_CONTEXT` formatting today (`SimpleORBNT8DefaultsTests.cs`/
`NT8StrategyBaseRejectSummaryTests.cs`-style source-text or execution
tests, whichever pattern already applies to this method).
## VALIDATION (operator)
None required for correctness — additive telemetry field only, no
existing log line format changed, no order-flow/sizing/risk behavior
touched. Once deployed, the next real short-side breakout will show
`AvwapSlope` directly in `STATE_CONTEXT`, confirming (or refuting) whether
it was genuinely negative (bearish, i.e., `trend_confirm`'s asymmetry
really is capping the score) on the setups this investigation looked at.
## GOVERNANCE
Track as [GAP-061] in SPRINT_BOARD.md. Update
`docs/00-governance/decisions.md`'s `DEC-20260825-04` entry to note
GAP-061 implemented. In your writeback, explicitly restate the
`trend_confirm` direction-blindness finding from THE DEFECT above (confirm
or correct it if a closer read changes the picture) so the operator has
a clean, source-verified basis for deciding whether to fix it as a
follow-up GAP.
Reference: this task, `DEC-20260825-04`, `TASK_GAP059_ORB_RANGE_TELEMETRY_PROMPT.md`
(same observability-only precedent).

View File

@@ -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-20260825-04
- **ID:** DEC-20260825-04
- **Date:** 2026-08-25
- **Status:** GAP-061 implemented; trend calibration follow-up undecided
- **Context:** Zero-trade investigation found real short-side breakout evaluations capped below Grade A, with `Trend=0.30` as the common driver on the best setups. Source read confirmed `TrendAlignmentFactorCalculator` adds `+0.4` for price on the trade side of AVWAP, `+0.3` for slope aligned with trade direction, and `+0.3` for `trend_confirm > 0.5`.
- **Finding:** `trend_confirm` is direction-blind in `SimpleORBStrategy.UpdateConfluenceInputs()` (`context.CustomData["trend_confirm"] = avwapSlope > 0.0 ? 1.0 : 0.0`). For short trades, slope alignment requires `avwapSlope < 0.0`, while `trend_confirm` requires `avwapSlope > 0.0`; a short can therefore earn one or the other, but not both, even in a clean bearish trend. GAP-061 does not fix this scoring asymmetry; it only exposes raw telemetry for operator review.
- **Decision:** Implement the selected observability-only instrumentation. Do not change `trend_confirm`, scoring, `MinTradeGrade`, risk, sizing, or order flow in this task.
- **Implementation Note (2026-08-25):** `SimpleORBNT8.GetStateTelemetryContextFields()` now appends `Avwap` (`F2`), `AvwapSlope` (`F4`), and `TrendConfirm` (`F1`) from existing `context.CustomData` keys when present, omitting each field entirely when the key is missing or non-numeric. The ORB-readiness gate and existing `OrbHigh`/`OrbLow`/`OrbWindowStart`/`OrbWindowEnd`/`OrbReady` fields are unchanged. No `UpdateConfluenceInputs()`, `TrendAlignmentFactorCalculator`, `trend_confirm`, scoring, `STATE:`, `STATE_DETAIL:`, risk, sizing, or order-flow logic changed. Verification: focused `SimpleORBNT8DefaultsTests` passed 7/7; `verify-build.bat` passed with 561/561 tests (472 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 472/472. Deploy intentionally skipped by task prompt.
- **Related Files:** `src/NT8.Adapters/Strategies/SimpleORBNT8.cs`, `tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs`, `TASK_GAP061_AVWAP_TELEMETRY_PROMPT.md`
- **Action Required:** Operator decision still needed on whether to fix direction-blind `trend_confirm` or revisit Trend/MinTradeGrade calibration after reviewing real `STATE_CONTEXT` values from a deployed session.
### DEC-20260825-02
- **ID:** DEC-20260825-02
- **Date:** 2026-08-25

View File

@@ -367,9 +367,36 @@ namespace NinjaTrader.NinjaScript.Strategies
fields.Add("OrbWindowStart", sdkOrb.OpeningRangeStart.ToString("HH:mm"));
fields.Add("OrbWindowEnd", sdkOrb.OpeningRangeEnd.ToString("HH:mm"));
fields.Add("OrbReady", sdkOrb.OpeningRangeReady.ToString());
AddStateContextDouble(fields, context, "Avwap", "avwap", "F2");
AddStateContextDouble(fields, context, "AvwapSlope", "avwap_slope", "F4");
AddStateContextDouble(fields, context, "TrendConfirm", "trend_confirm", "F1");
return fields;
}
private static void AddStateContextDouble(Dictionary<string, string> fields, StrategyContext context, string outputKey, string customDataKey, string format)
{
if (fields == null || context == null || context.CustomData == null || !context.CustomData.ContainsKey(customDataKey))
return;
object value = context.CustomData[customDataKey];
if (value == null)
return;
double numericValue;
if (value is double)
numericValue = (double)value;
else if (value is float)
numericValue = (double)(float)value;
else if (value is int)
numericValue = (double)(int)value;
else if (value is long)
numericValue = (double)(long)value;
else
return;
fields.Add(outputKey, numericValue.ToString(format));
}
protected override void ConfigureStrategyParameters()
{
_strategyConfig.RiskSettings.DailyLossLimit = DailyLossLimit;

View File

@@ -57,6 +57,41 @@ namespace NT8.Core.Tests.Adapters
Assert.IsFalse(source.Contains("_openingRangeLow"), "Legacy adapter ORB low field must stay removed because the SDK tracker owns this state.");
}
[TestMethod]
public void StateTelemetryContext_IncludesAvwapTrendInputsWithRequiredFormatting()
{
string source = File.ReadAllText(FindSourceFile());
string method = ExtractMethodBlock(source, "protected override Dictionary<string, string> GetStateTelemetryContextFields");
Assert.IsTrue(method.Contains("AddStateContextDouble(fields, context, \"Avwap\", \"avwap\", \"F2\");"), "STATE_CONTEXT must include avwap as Avwap with F2 formatting.");
Assert.IsTrue(method.Contains("AddStateContextDouble(fields, context, \"AvwapSlope\", \"avwap_slope\", \"F4\");"), "STATE_CONTEXT must include avwap_slope as AvwapSlope with F4 formatting.");
Assert.IsTrue(method.Contains("AddStateContextDouble(fields, context, \"TrendConfirm\", \"trend_confirm\", \"F1\");"), "STATE_CONTEXT must include trend_confirm as TrendConfirm with F1 formatting.");
Assert.IsFalse(method.Contains("TrendConfirm") && method.Contains("0.0"), "STATE_CONTEXT must not add placeholder TrendConfirm values inside the context method.");
}
[TestMethod]
public void StateTelemetryContext_OmitsAvwapTrendInputsWhenCustomDataKeysMissing()
{
string source = File.ReadAllText(FindSourceFile());
string helper = ExtractMethodBlock(source, "private static void AddStateContextDouble");
Assert.IsTrue(helper.Contains("context.CustomData == null"), "Telemetry helper must tolerate missing CustomData.");
Assert.IsTrue(helper.Contains("!context.CustomData.ContainsKey(customDataKey)"), "Telemetry helper must omit missing CustomData keys.");
Assert.IsTrue(helper.Contains("return;"), "Telemetry helper must return without placeholders for missing keys.");
Assert.IsFalse(helper.Contains("fields.Add(outputKey, \""), "Telemetry helper must not emit placeholder string values.");
}
[TestMethod]
public void StateTelemetryContext_DoesNotChangeScoringOrStateLineFormats()
{
string source = File.ReadAllText(FindSourceFile());
string method = ExtractMethodBlock(source, "protected override Dictionary<string, string> GetStateTelemetryContextFields");
Assert.IsFalse(source.Contains("context.CustomData[\"trend_confirm\"] ="), "SimpleORBNT8 telemetry must not change trend_confirm calculation.");
Assert.IsFalse(method.Contains("STATE:"), "GAP-061 must not change STATE line formatting.");
Assert.IsFalse(method.Contains("STATE_DETAIL:"), "GAP-061 must not change STATE_DETAIL line formatting.");
}
private static string FindSourceFile()
{
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);