Sprint 3: Production Hardening — 9 tasks completed
## 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
This commit is contained in:
314
docs/archive/fix-specs/COMPILE_FIX_SPECIFICATION.md
Normal file
314
docs/archive/fix-specs/COMPILE_FIX_SPECIFICATION.md
Normal file
@@ -0,0 +1,314 @@
|
||||
# NT8 Compile Fix Specification
|
||||
|
||||
**For:** Kilocode AI Agent
|
||||
**Priority:** URGENT
|
||||
**Mode:** Code Mode
|
||||
**Estimated Time:** 30-45 minutes
|
||||
**Files to Edit:** 2 files
|
||||
**New Files:** 0
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Objective
|
||||
|
||||
Fix 9 NT8 NinjaScript compilation errors in two strategy files. These are
|
||||
mechanical fixes - naming conflicts, type conversions, and a missing reference.
|
||||
Do NOT redesign logic. Surgical edits only.
|
||||
|
||||
---
|
||||
|
||||
## 📋 Error Summary
|
||||
|
||||
| # | File | Error | Line | Fix Type |
|
||||
|---|------|-------|------|----------|
|
||||
| 1 | SimpleORBNT8.cs | `NT8.Strategies` namespace not found | 15 | Add using alias |
|
||||
| 2 | NT8StrategyBase.cs | `Position` ambiguous reference | 49 | Qualify type |
|
||||
| 3 | NT8StrategyBase.cs | `Position` ambiguous reference | 300 | Qualify type |
|
||||
| 4 | SimpleORBNT8.cs | `SimpleORBStrategy` not found | 72 | Add using alias |
|
||||
| 5 | NT8StrategyBase.cs | `double` cannot convert to `long` | 273 | Cast to long |
|
||||
| 6 | NT8StrategyBase.cs | `double` cannot convert to `int` | 364 | Cast to int |
|
||||
| 7 | NT8StrategyBase.cs | `double` cannot convert to `int` | 366 | Cast to int |
|
||||
| 8 | NT8StrategyBase.cs | `double` cannot convert to `int` | 373 | Cast to int |
|
||||
| 9 | NT8StrategyBase.cs | `double` cannot convert to `int` | 375 | Cast to int |
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Fix 1: NT8StrategyBase.cs - Ambiguous `Position` reference (Errors 2 & 3)
|
||||
|
||||
### Problem
|
||||
NT8's `NinjaTrader.Cbi.Position` and our `NT8.Core.Common.Models.Position` both exist
|
||||
in scope. C# cannot resolve which one to use on lines 49 and 300.
|
||||
|
||||
### Solution
|
||||
Add a using alias at the top of the file to disambiguate, then use the alias
|
||||
wherever SDK Position is intended.
|
||||
|
||||
### Change 1a: Add alias to using block (top of file, after existing using aliases)
|
||||
|
||||
**Find this block** (lines 19-25):
|
||||
```csharp
|
||||
using SdkOrderSide = NT8.Core.Common.Models.OrderSide;
|
||||
using SdkOrderType = NT8.Core.Common.Models.OrderType;
|
||||
using OmsOrderRequest = NT8.Core.OMS.OrderRequest;
|
||||
using OmsOrderSide = NT8.Core.OMS.OrderSide;
|
||||
using OmsOrderType = NT8.Core.OMS.OrderType;
|
||||
using OmsOrderState = NT8.Core.OMS.OrderState;
|
||||
using OmsOrderStatus = NT8.Core.OMS.OrderStatus;
|
||||
```
|
||||
|
||||
**Replace with** (add one line at top):
|
||||
```csharp
|
||||
using SdkPosition = NT8.Core.Common.Models.Position;
|
||||
using SdkOrderSide = NT8.Core.Common.Models.OrderSide;
|
||||
using SdkOrderType = NT8.Core.Common.Models.OrderType;
|
||||
using OmsOrderRequest = NT8.Core.OMS.OrderRequest;
|
||||
using OmsOrderSide = NT8.Core.OMS.OrderSide;
|
||||
using OmsOrderType = NT8.Core.OMS.OrderType;
|
||||
using OmsOrderState = NT8.Core.OMS.OrderState;
|
||||
using OmsOrderStatus = NT8.Core.OMS.OrderStatus;
|
||||
```
|
||||
|
||||
### Change 1b: Fix field declaration (line 49)
|
||||
|
||||
**Find:**
|
||||
```csharp
|
||||
private Position _lastPosition;
|
||||
```
|
||||
|
||||
**Replace with:**
|
||||
```csharp
|
||||
private SdkPosition _lastPosition;
|
||||
```
|
||||
|
||||
### Change 1c: Fix return type in BuildPositionInfo() (line 300 area)
|
||||
|
||||
**Find:**
|
||||
```csharp
|
||||
private Position BuildPositionInfo()
|
||||
{
|
||||
var p = NT8DataConverter.ConvertPosition(
|
||||
Instrument.MasterInstrument.Name,
|
||||
Position.Quantity,
|
||||
Position.AveragePrice,
|
||||
0.0,
|
||||
0.0,
|
||||
DateTime.UtcNow);
|
||||
|
||||
_lastPosition = p;
|
||||
return p;
|
||||
}
|
||||
```
|
||||
|
||||
**Replace with:**
|
||||
```csharp
|
||||
private SdkPosition BuildPositionInfo()
|
||||
{
|
||||
var p = NT8DataConverter.ConvertPosition(
|
||||
Instrument.MasterInstrument.Name,
|
||||
Position.Quantity,
|
||||
Position.AveragePrice,
|
||||
0.0,
|
||||
0.0,
|
||||
DateTime.UtcNow);
|
||||
|
||||
_lastPosition = p;
|
||||
return p;
|
||||
}
|
||||
```
|
||||
|
||||
**NOTE:** `Position.Quantity` and `Position.AveragePrice` (without qualifier) correctly
|
||||
refer to `NinjaTrader.Cbi.Position` (NT8's built-in position property on the Strategy
|
||||
class). Only the return type and field type need the alias. Do NOT change the
|
||||
`Position.Quantity` / `Position.AveragePrice` references.
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Fix 2: NT8StrategyBase.cs - Volume double to long (Error 5)
|
||||
|
||||
### Problem
|
||||
`NT8DataConverter.ConvertBar()` expects `volume` as `long`, but NT8's `Volume[0]`
|
||||
returns `double`.
|
||||
|
||||
### Location
|
||||
Inside `ConvertCurrentBar()` method (line 273 area).
|
||||
|
||||
### Change: Cast Volume[0] to long
|
||||
|
||||
**Find:**
|
||||
```csharp
|
||||
private BarData ConvertCurrentBar()
|
||||
{
|
||||
return NT8DataConverter.ConvertBar(
|
||||
Instrument.MasterInstrument.Name,
|
||||
Time[0],
|
||||
Open[0],
|
||||
High[0],
|
||||
Low[0],
|
||||
Close[0],
|
||||
Volume[0],
|
||||
(int)BarsPeriod.Value);
|
||||
}
|
||||
```
|
||||
|
||||
**Replace with:**
|
||||
```csharp
|
||||
private BarData ConvertCurrentBar()
|
||||
{
|
||||
return NT8DataConverter.ConvertBar(
|
||||
Instrument.MasterInstrument.Name,
|
||||
Time[0],
|
||||
Open[0],
|
||||
High[0],
|
||||
Low[0],
|
||||
Close[0],
|
||||
(long)Volume[0],
|
||||
(int)BarsPeriod.Value);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Fix 3: NT8StrategyBase.cs - StopTicks/TargetTicks double to int (Errors 6-9)
|
||||
|
||||
### Problem
|
||||
`SetStopLoss()` and `SetProfitTarget()` NT8 methods expect `int` for tick counts,
|
||||
but `intent.StopTicks` and `intent.TargetTicks` are `double`.
|
||||
|
||||
### Location
|
||||
Inside `SubmitOrderToNT8()` method (lines 364-375 area).
|
||||
|
||||
### Change: Cast tick values to int
|
||||
|
||||
**Find:**
|
||||
```csharp
|
||||
if (intent.StopTicks > 0)
|
||||
SetStopLoss(orderName, CalculationMode.Ticks, intent.StopTicks, false);
|
||||
|
||||
if (intent.TargetTicks.HasValue && intent.TargetTicks.Value > 0)
|
||||
SetProfitTarget(orderName, CalculationMode.Ticks, intent.TargetTicks.Value);
|
||||
```
|
||||
|
||||
**Replace with:**
|
||||
```csharp
|
||||
if (intent.StopTicks > 0)
|
||||
SetStopLoss(orderName, CalculationMode.Ticks, (int)intent.StopTicks, false);
|
||||
|
||||
if (intent.TargetTicks.HasValue && intent.TargetTicks.Value > 0)
|
||||
SetProfitTarget(orderName, CalculationMode.Ticks, (int)intent.TargetTicks.Value);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Fix 4: SimpleORBNT8.cs - Missing NT8.Strategies reference (Errors 1 & 4)
|
||||
|
||||
### Problem
|
||||
`SimpleORBStrategy` lives in the `NT8.Strategies.Examples` namespace. The using
|
||||
directive references `NT8.Strategies.Examples` but NT8.Strategies.dll must also be
|
||||
deployed to NT8 Custom folder AND added as a reference in the NinjaScript Editor.
|
||||
|
||||
### Change: Add using alias at top of SimpleORBNT8.cs
|
||||
|
||||
**Find** (line 15):
|
||||
```csharp
|
||||
using NT8.Strategies.Examples;
|
||||
```
|
||||
|
||||
**Replace with:**
|
||||
```csharp
|
||||
using NT8.Strategies.Examples;
|
||||
using SdkSimpleORB = NT8.Strategies.Examples.SimpleORBStrategy;
|
||||
```
|
||||
|
||||
**AND** update the usage inside `CreateSdkStrategy()`:
|
||||
|
||||
**Find:**
|
||||
```csharp
|
||||
protected override IStrategy CreateSdkStrategy()
|
||||
{
|
||||
return new SimpleORBStrategy(OpeningRangeMinutes, StdDevMultiplier);
|
||||
}
|
||||
```
|
||||
|
||||
**Replace with:**
|
||||
```csharp
|
||||
protected override IStrategy CreateSdkStrategy()
|
||||
{
|
||||
return new SdkSimpleORB(OpeningRangeMinutes, StdDevMultiplier);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📦 Deployment Step (Manual - Not Kilocode)
|
||||
|
||||
**After code fixes are committed**, Mo needs to:
|
||||
|
||||
```powershell
|
||||
# Build NT8.Strategies project
|
||||
cd C:\dev\nt8-sdk
|
||||
dotnet build src\NT8.Strategies\NT8.Strategies.csproj --configuration Release
|
||||
|
||||
# Copy DLL to NT8 Custom folder (NT8 must be closed)
|
||||
Copy-Item "src\NT8.Strategies\bin\Release\net48\NT8.Strategies.dll" `
|
||||
"$env:USERPROFILE\Documents\NinjaTrader 8\bin\Custom\" -Force
|
||||
```
|
||||
|
||||
Then in NT8 NinjaScript Editor:
|
||||
- Right-click → References → Add → NT8.Strategies.dll
|
||||
|
||||
---
|
||||
|
||||
## ✅ Verification Steps
|
||||
|
||||
### After Code Changes:
|
||||
```bash
|
||||
# Build must succeed with zero errors
|
||||
dotnet build src\NT8.Adapters\NT8.Adapters.csproj --configuration Release
|
||||
|
||||
# All tests must still pass
|
||||
dotnet test NT8-SDK.sln --configuration Release --no-build
|
||||
```
|
||||
|
||||
### After NT8 Recompile:
|
||||
- [ ] Zero compilation errors in NinjaScript Editor
|
||||
- [ ] MinimalTestStrategy visible in strategy list
|
||||
- [ ] SimpleORBNT8 visible in strategy list
|
||||
- [ ] NT8StrategyBase not directly visible (abstract)
|
||||
|
||||
---
|
||||
|
||||
## 🚨 Constraints
|
||||
|
||||
- C# 5.0 syntax only - no modern features
|
||||
- Surgical edits ONLY - do not refactor or redesign
|
||||
- Do NOT change any logic, only fix the type issues
|
||||
- Preserve all XML documentation comments
|
||||
- All 319 existing tests must still pass after changes
|
||||
|
||||
---
|
||||
|
||||
## 📋 Git Commit
|
||||
|
||||
```bash
|
||||
git add src/NT8.Adapters/Strategies/NT8StrategyBase.cs
|
||||
git add src/NT8.Adapters/Strategies/SimpleORBNT8.cs
|
||||
git commit -m "fix: Resolve NT8 NinjaScript compilation errors
|
||||
|
||||
- Add SdkPosition alias to disambiguate from NinjaTrader.Cbi.Position
|
||||
- Cast Volume[0] from double to long for ConvertBar()
|
||||
- Cast StopTicks/TargetTicks from double to int for SetStopLoss/SetProfitTarget
|
||||
- Add SdkSimpleORB alias for SimpleORBStrategy in SimpleORBNT8.cs
|
||||
|
||||
All 9 NT8 compile errors resolved. Zero logic changes."
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Success Criteria
|
||||
|
||||
- [ ] Zero compilation errors in NT8 NinjaScript Editor
|
||||
- [ ] All 319 existing tests still passing
|
||||
- [ ] Zero new build warnings
|
||||
- [ ] Code committed to Git
|
||||
|
||||
**READY FOR KILOCODE - CODE MODE** ✅
|
||||
Reference in New Issue
Block a user