## Summary Implemented 9 production-hardening tasks across risk, execution, calendar, and governance. All changes verified: build clean (0 errors), 492 tests passing (404 core + 78 integration + 10 perf). ## Core Changes ### Risk & Portfolio (3 tasks) - **GAP-019** Portfolio Heat Tier 3.5: Added MaxHeatPct (default 3%) to AdvancedRiskConfig; ValidatePortfolioHeat() computes TotalOpenRisk + NewTradeRisk / Equity * 100; rejects when exceeded. - **GAP-003** RiskPerTrade <= MaxTradeRisk Assertion: RiskPerTrade property in RiskConfig; throws ArgumentException at ValidateOrder() if RiskPerTrade > MaxTradeRisk; 3 unit tests. - **GAP-005** GetRiskStatus() Live Config: _currentDailyLossLimit field updated from config.DailyLossLimit on each ValidateOrder(); GetRiskStatus() returns actual value; 3 unit tests. ### Execution & Position Management (3 tasks) - **TASK-06a** Runner Mode Architecture: RunnerMode enum (Auto/Mode1DualLeg/Mode2RunnerOnly/ Mode3ScalerOnly/Disabled); ResolveRunnerMode() logic; 4-mode SubmitOrderToNT8() behavior. - **TASK-06b** ATR Dynamic Stop: EnableDynamicStop, AtrPeriod, AtrMultiplier, MinStopTicks, MaxStopTicks; computes dynStop = clamp(round(ATR/TickSize * Mult), Min, Max); overrides intent.StopTicks. - **GAP-006** Position-Close Re-arm: OnPositionUpdate() sends clear_trade_taken when flat; EnableBarBasedRearm parameter gates legacy bar-driven re-arm (default false for live). ### Strategy Intelligence (2 tasks) - **GAP-004** orbRangeTicks Fix: DailyBarContext.OrbRangeTicks field; computed from actual ORB high/low / TickSize; passed to Factor 7 (ORBvsATR). - **GAP-010** Short-Side Regime Filter: EnableShortTrendFilter param; vetoes shorts when AVWAP slope > 0 (bullish); configurable, default true. ### Calendar & Trailing (2 tasks) - **GAP-008** CME Holiday Awareness: NEW CmeHolidayCalendar.cs with 9 observed holidays + Good Friday (Easter calc); EnableCMEHolidayGuard skips ORB window on holidays. - **GAP-009** ATR Trailing Real ATR: EnableATRTrailing, ATRTrailingPeriod (14), ATRTrailingMultiplier (2.0), ATRTrailingMinTicks (8), ATRTrailingMaxTicks (60); computes trailTicks from ATR(Close,Period)[0]. ## Governance - SPRINT_BOARD.md, current_status.md, decisions.md (DEC-20260711-01 through -09), NEXT_PROMPT.md updated - All 9 tasks moved ACTIVE -> COMPLETED; GAP-011 (Gitea CI) now ACTIVE ## Verification - verify-build.bat: 0 errors, 0 warnings - Tests: 492 passing (404 core + 78 integration + 10 performance) ## Files - Modified: 13 source, 3 test, 9 governance - Deleted: 28 obsolete spec/docs - Added: 1 new module (NT8.Core.Calendar), governance files - Dual-deployed to NT8 Custom\Strategies\ ## Rollback Tag: sprint3-production-hardening-complete To revert: git reset --hard sprint3-production-hardening-complete
277 lines
8.7 KiB
Markdown
277 lines
8.7 KiB
Markdown
# NT8 Strategy Diagnostic Logging Enhancement
|
|
|
|
**For:** Kilocode AI Agent
|
|
**Priority:** HIGH
|
|
**Mode:** Code Mode
|
|
**Estimated Time:** 30-40 minutes
|
|
**Files to Edit:** 1 file (NT8StrategyBase.cs)
|
|
|
|
---
|
|
|
|
## 🎯 Objective
|
|
|
|
Add comprehensive diagnostic logging to NT8StrategyBase so we can see exactly
|
|
what's happening during backtesting when zero trades occur. This will help
|
|
diagnose if the issue is:
|
|
- Strategy not generating intents
|
|
- Risk manager rejecting trades
|
|
- Position sizer issues
|
|
- Data feed issues
|
|
|
|
---
|
|
|
|
## 🔧 Changes to NT8StrategyBase.cs
|
|
|
|
### Change 1: Enhanced OnBarUpdate logging
|
|
|
|
**Find:**
|
|
```csharp
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (!_sdkInitialized || _sdkStrategy == null)
|
|
return;
|
|
if (CurrentBar < BarsRequiredToTrade)
|
|
return;
|
|
if (Time[0] == _lastBarTime)
|
|
return;
|
|
|
|
_lastBarTime = Time[0];
|
|
|
|
try
|
|
{
|
|
var barData = ConvertCurrentBar();
|
|
var context = BuildStrategyContext();
|
|
|
|
StrategyIntent intent;
|
|
lock (_lock)
|
|
{
|
|
intent = _sdkStrategy.OnBar(barData, context);
|
|
}
|
|
|
|
if (intent != null)
|
|
ProcessStrategyIntent(intent, context);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_logger != null)
|
|
_logger.LogError("OnBarUpdate failed: {0}", ex.Message);
|
|
|
|
Print(string.Format("[SDK ERROR] OnBarUpdate: {0}", ex.Message));
|
|
Log(string.Format("[SDK ERROR] {0}", ex.ToString()), LogLevel.Error);
|
|
}
|
|
}
|
|
```
|
|
|
|
**Replace with:**
|
|
```csharp
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (!_sdkInitialized || _sdkStrategy == null)
|
|
{
|
|
if (CurrentBar == 0)
|
|
Print(string.Format("[SDK] Not initialized: sdkInit={0}, strategy={1}",
|
|
_sdkInitialized, _sdkStrategy != null));
|
|
return;
|
|
}
|
|
|
|
if (CurrentBar < BarsRequiredToTrade)
|
|
{
|
|
if (CurrentBar == 0)
|
|
Print(string.Format("[SDK] Waiting for bars: current={0}, required={1}",
|
|
CurrentBar, BarsRequiredToTrade));
|
|
return;
|
|
}
|
|
|
|
if (Time[0] == _lastBarTime)
|
|
return;
|
|
|
|
_lastBarTime = Time[0];
|
|
|
|
// Log first bar and every 100th bar to show activity
|
|
if (CurrentBar == BarsRequiredToTrade || CurrentBar % 100 == 0)
|
|
{
|
|
Print(string.Format("[SDK] Processing bar {0}: {1} O={2:F2} H={3:F2} L={4:F2} C={5:F2}",
|
|
CurrentBar, Time[0].ToString("yyyy-MM-dd HH:mm"),
|
|
Open[0], High[0], Low[0], Close[0]));
|
|
}
|
|
|
|
try
|
|
{
|
|
var barData = ConvertCurrentBar();
|
|
var context = BuildStrategyContext();
|
|
|
|
StrategyIntent intent;
|
|
lock (_lock)
|
|
{
|
|
intent = _sdkStrategy.OnBar(barData, context);
|
|
}
|
|
|
|
if (intent != null)
|
|
{
|
|
Print(string.Format("[SDK] Intent generated: {0} {1} @ {2}",
|
|
intent.Side, intent.Symbol, intent.EntryType));
|
|
ProcessStrategyIntent(intent, context);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_logger != null)
|
|
_logger.LogError("OnBarUpdate failed: {0}", ex.Message);
|
|
|
|
Print(string.Format("[SDK ERROR] OnBarUpdate: {0}", ex.Message));
|
|
Log(string.Format("[SDK ERROR] {0}", ex.ToString()), LogLevel.Error);
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### Change 2: Enhanced ProcessStrategyIntent logging
|
|
|
|
**Find:**
|
|
```csharp
|
|
private void ProcessStrategyIntent(StrategyIntent intent, StrategyContext context)
|
|
{
|
|
var riskDecision = _riskManager.ValidateOrder(intent, context, _riskConfig);
|
|
if (!riskDecision.Allow)
|
|
{
|
|
if (_logger != null)
|
|
_logger.LogWarning("Intent rejected by risk manager: {0}", riskDecision.RejectReason);
|
|
return;
|
|
}
|
|
|
|
var sizingResult = _positionSizer.CalculateSize(intent, context, _sizingConfig);
|
|
if (sizingResult.Contracts < MinContracts)
|
|
return;
|
|
|
|
var request = new OmsOrderRequest();
|
|
request.Symbol = intent.Symbol;
|
|
request.Side = MapOrderSide(intent.Side);
|
|
request.Type = MapOrderType(intent.EntryType);
|
|
request.Quantity = sizingResult.Contracts;
|
|
request.LimitPrice = intent.LimitPrice.HasValue ? (decimal?)intent.LimitPrice.Value : null;
|
|
request.StopPrice = null;
|
|
|
|
SubmitOrderToNT8(request, intent);
|
|
_ordersSubmittedToday++;
|
|
}
|
|
```
|
|
|
|
**Replace with:**
|
|
```csharp
|
|
private void ProcessStrategyIntent(StrategyIntent intent, StrategyContext context)
|
|
{
|
|
Print(string.Format("[SDK] Validating intent: {0} {1}", intent.Side, intent.Symbol));
|
|
|
|
var riskDecision = _riskManager.ValidateOrder(intent, context, _riskConfig);
|
|
if (!riskDecision.Allow)
|
|
{
|
|
Print(string.Format("[SDK] Risk REJECTED: {0}", riskDecision.RejectReason));
|
|
if (_logger != null)
|
|
_logger.LogWarning("Intent rejected by risk manager: {0}", riskDecision.RejectReason);
|
|
return;
|
|
}
|
|
|
|
Print(string.Format("[SDK] Risk approved"));
|
|
|
|
var sizingResult = _positionSizer.CalculateSize(intent, context, _sizingConfig);
|
|
Print(string.Format("[SDK] Position size: {0} contracts (min={1}, max={2})",
|
|
sizingResult.Contracts, MinContracts, MaxContracts));
|
|
|
|
if (sizingResult.Contracts < MinContracts)
|
|
{
|
|
Print(string.Format("[SDK] Size too small: {0} < {1}", sizingResult.Contracts, MinContracts));
|
|
return;
|
|
}
|
|
|
|
var request = new OmsOrderRequest();
|
|
request.Symbol = intent.Symbol;
|
|
request.Side = MapOrderSide(intent.Side);
|
|
request.Type = MapOrderType(intent.EntryType);
|
|
request.Quantity = sizingResult.Contracts;
|
|
request.LimitPrice = intent.LimitPrice.HasValue ? (decimal?)intent.LimitPrice.Value : null;
|
|
request.StopPrice = null;
|
|
|
|
Print(string.Format("[SDK] Submitting order: {0} {1} {2} @ {3}",
|
|
request.Side, request.Quantity, request.Symbol, request.Type));
|
|
|
|
SubmitOrderToNT8(request, intent);
|
|
_ordersSubmittedToday++;
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### Change 3: Enhanced InitializeSdkComponents logging
|
|
|
|
**Find:**
|
|
```csharp
|
|
private void InitializeSdkComponents()
|
|
{
|
|
_logger = new BasicLogger(Name);
|
|
|
|
_riskConfig = new RiskConfig(DailyLossLimit, MaxTradeRisk, MaxOpenPositions, true);
|
|
```
|
|
|
|
**Replace with:**
|
|
```csharp
|
|
private void InitializeSdkComponents()
|
|
{
|
|
_logger = new BasicLogger(Name);
|
|
|
|
Print(string.Format("[SDK] Initializing with: DailyLoss={0:C}, TradeRisk={1:C}, MaxPos={2}",
|
|
DailyLossLimit, MaxTradeRisk, MaxOpenPositions));
|
|
|
|
_riskConfig = new RiskConfig(DailyLossLimit, MaxTradeRisk, MaxOpenPositions, true);
|
|
```
|
|
|
|
---
|
|
|
|
## ✅ Verification
|
|
|
|
```bash
|
|
# Build must succeed
|
|
dotnet build src\NT8.Adapters\NT8.Adapters.csproj --configuration Release
|
|
|
|
# Deploy
|
|
.\deployment\Deploy-To-NT8.ps1
|
|
```
|
|
|
|
**Expected in NT8 Output Window after backtest:**
|
|
```
|
|
[SDK] Initializing with: DailyLoss=$1,000.00, TradeRisk=$200.00, MaxPos=3
|
|
[SDK] Simple ORB NT8 initialized successfully
|
|
[SDK] Waiting for bars: current=0, required=50
|
|
[SDK] Processing bar 50: 2026-02-10 09:30 O=4200.00 H=4210.00 L=4195.00 C=4208.00
|
|
[SDK] Processing bar 150: 2026-02-10 12:30 O=4215.00 H=4220.00 L=4210.00 C=4218.00
|
|
[SDK] Intent generated: Buy ES @ Market
|
|
[SDK] Validating intent: Buy ES
|
|
[SDK] Risk approved
|
|
[SDK] Position size: 1 contracts (min=1, max=3)
|
|
[SDK] Submitting order: Buy 1 ES @ Market
|
|
```
|
|
|
|
This will show exactly where the strategy is failing.
|
|
|
|
---
|
|
|
|
## 📋 Git Commit
|
|
|
|
```bash
|
|
git add src/NT8.Adapters/Strategies/NT8StrategyBase.cs
|
|
git commit -m "feat: Add comprehensive diagnostic logging
|
|
|
|
- Log initialization parameters
|
|
- Log bar processing activity (every 100 bars)
|
|
- Log intent generation
|
|
- Log risk validation results
|
|
- Log position sizing calculations
|
|
- Log order submission
|
|
|
|
Makes it easy to diagnose why strategy isn't trading"
|
|
```
|
|
|
|
---
|
|
|
|
**READY FOR KILOCODE - CODE MODE** ✅
|