# 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** ✅
