Files
nt8-sdk/docs/00-governance/architecture.md
mo d84949caa3 chore: checkpoint remaining pre-gate worktree changes
- governance: stage v7.0 review prompts, run book, roadmap/current-status/decision updates, and sprint board state

- adapters: capture DASH/trailing-drawdown/state-telemetry strategy work already present in the worktree

- tools: capture dashboard console/KPI parser updates, logtriage notes, and runnersweep output

Build: previously clean | Tests: previously 511 passing | Includes all open staged files
2026-08-21 14:53:15 -04:00

5.9 KiB

Architecture Governance

Runtime Flow (Authoritative)

SimpleORBNT8.cs
  -> NT8StrategyBase.cs
  -> SimpleORBStrategy.cs
  -> NT8OrderAdapter.cs
  -> PortfolioRiskManager.cs
  -> NinjaTrader 8

Responsibilities

  • SimpleORBNT8.cs: NT8 entry point and platform lifecycle bridge.
  • NT8StrategyBase.cs: orchestration, risk gate sequencing, execution handoff, platform callbacks.
  • SimpleORBStrategy.cs: signal generation and confluence grading only.
  • NT8OrderAdapter.cs: execution bridge to NT8 managed order APIs.
  • PortfolioRiskManager.cs: cross-strategy risk controls and account-level enforcement.

Architectural Constraints

  • Risk-first flow is mandatory; no strategy-level bypass of risk validation.
  • Managed-order sequence remains required (SetStopLoss / SetProfitTarget before entry).
  • C# 5.0 syntax only, .NET Framework 4.8 only.
  • NT8 signatures must be verified against official NinjaTrader docs before API-touching edits.

Governance Notes

  • Core Risk/Sizing/OMS/Intelligence/Analytics layers are treated as complete and stable unless explicitly re-opened by approved work.
  • Hardening changes are concentrated in targeted adapter/utility components per active-work scope.

Platform-Neutral SDK Invariant (confirmed 2026-08-17)

NT8.Core (Risk, Sizing, OMS, Intelligence, Analytics, Common) contains zero NinjaTrader.* references anywhere in the project — confirmed by direct read of every file touched in recent sessions (RegimeManager.cs, TrendRegimeDetector.cs, VolatilityRegimeDetector.cs, FactorCalculators.cs, PortfolioRiskManager.cs, and others). NT8.Adapters is the only layer that references NinjaTrader assemblies; it exists specifically to translate between NT8.Core's broker-agnostic models (BarData, StrategyContext, StrategyIntent, OrderSide, etc.) and NT8's own types. This is a real, maintained property today, not an aspiration — a future adapter for a different broker/API would implement the same bridge pattern NT8.Adapters uses, without touching NT8.Core. Rule: NT8.Core must never gain a using NinjaTrader.* reference. Any PR/Kilocode prompt that would add one should be rejected or redirected to put that logic in NT8.Adapters instead.

Multi-Strategy / 24x7 Trading Architecture (clarified 2026-08-17)

The "shared everything but entry" pattern referenced in earlier planning is already the real architecture, not a future change:

  • NT8StrategyBase.cs (shared): risk gate sequencing, sizing, provenance, logging, runner/breakeven management, regime gate, portfolio coordination.
  • Each strategy's entry logic is a separate IStrategy implementation (e.g. SimpleORBStrategy.cs) paired with a thin NinjaScript adapter subclass of NT8StrategyBase (e.g. SimpleORBNT8.cs).
  • Sprint 4 (roadmap.md) already plans exactly this pattern for VWAPMeanReversion, OvernightGapContinuation/OvernightGapReversion, and LondonORBNT8 — each a new entry module, not a rewrite of the shared base.

24x7 coverage is concurrent strategy instances with disjoint session windows, not an on/off switch between strategies. Each session-scoped strategy (RTH ORB, London ORB, overnight gap) runs as its own NinjaScript strategy instance, simultaneously, each gated to its own trading window. PortfolioRiskManager.Instance already exists specifically to coordinate risk across concurrently-registered strategies (RegisterStrategy(), ValidatePortfolioRisk() enforces a combined daily loss limit and a total open-contract cap across every registered strategy) — this was already built for this scenario, it just hasn't been exercised with more than one strategy family yet. Running SimpleORBNT8 plus a future LondonORBNT8 simultaneously on the same account is the intended production pattern, not a single-frozen-account gate-validation-only concept (that doctrine governs gate validation discipline, not permanent production topology).

Known gap: no multi-account dimension. PortfolioRiskManager is a process-wide singleton keyed only by strategyId — there is no account key anywhere in its state (_strategyPnL, _strategyOpenContracts, _registeredStrategies are all Dictionary<string, ...> with no account segregation). Two strategies on different accounts would currently have their P&L and contract counts aggregated together incorrectly. This must be fixed (add an account key to the singleton's internal dictionaries, or move to per-account instances) before "multiple accounts simultaneously" is safe to run. Tracked as GAP-042 in roadmap.md.

Control Plane (answers "must this be an NT8 AddOn?")

Two real paths exist; the NT8 AddOn is not the only option:

  1. NT8 AddOn (WPF panel) — already on the roadmap (Sprint 6, "NT8 Add-On WPF panel"). Fully NT8-native, can call directly into running strategy instances. Ties the control UI to NT8's process and UI framework.
  2. External command channel — more aligned with the platform-neutral goal. IStrategy.SetParameters(Dictionary<string, object>) already exists and is already used internally (force_session_reset, clear_trade_taken). This could be extended so NT8StrategyBase polls a small local command file/HTTP endpoint on each bar close (which already fires every bar regardless of strategy) and applies any pending command via the existing SetParameters() path, then acknowledges it. This keeps the command surface broker-agnostic — the same mechanism would work if NT8.Adapters were ever joined by an adapter for a different platform, whereas an NT8 AddOn only ever works for NT8. Recommendation: build the external command channel first (smaller, platform-neutral, reuses existing SetParameters() plumbing) and treat the NT8 AddOn as an optional additional UI surface later, not a prerequisite. Neither is scoped for implementation yet — this section records the design direction so it isn't re-litigated from scratch later.