Pre-cleanup baseline snapshot
Some checks failed
Build and Test / build (push) Has been cancelled

This commit is contained in:
2026-04-05 16:50:18 -04:00
parent d856f3949d
commit 9a28a49292
12 changed files with 695 additions and 30 deletions

View File

@@ -1,9 +1,66 @@
# Coding Patterns — NT8 SDK Required Patterns
**Last Updated:** 2026-03-27
All code in the NT8 SDK MUST follow these patterns without exception.
---
## 0. C# 5.0 Hard Constraints (NinjaScript Compiler)
```csharp
// ❌ PROHIBITED — compiler will fail silently or error
$"Hello {name}" // no string interpolation
obj?.Method() // no null-conditional
public int Prop => _value; // no expression body
nameof(SomeClass) // no nameof
await SomeAsync() // no async/await
// ✅ REQUIRED
string.Format("Hello {0}", name)
obj != null ? obj.Method() : null
public int Prop { get { return _value; } }
"SomeClass" // string literal
// synchronous only
```
---
## 0b. NT8-Specific Critical Rules
```csharp
// SetStopLoss/SetProfitTarget MUST come BEFORE EnterLong/EnterShort
// Calling them after is silently ignored in backtest
SetStopLoss(signalName, CalculationMode.Ticks, stopTicks, false); // FIRST
SetProfitTarget(signalName, CalculationMode.Ticks, targetTicks); // SECOND
EnterShort(qty, signalName); // THIRD
// OnBarUpdate must guard secondary series
protected override void OnBarUpdate()
{
if (BarsInProgress != 0) return; // CRITICAL: ignore daily bar series updates
// ...
}
// State guard in ProcessStrategyIntent
// Allows Historical (backtest), blocks Realtime replay burst:
if (State == State.Realtime && !_realtimeBarSeen)
return;
```
---
## Sizing Formula
```
contracts = floor(RiskPerTrade / (StopTicks × TickValue))
NQ tick value = $5.00
$100 / (8 × $5) = 2 contracts
$200 / (8 × $5) = 5 contracts (capped at MaxContracts)
Always verify: RiskPerTrade ≤ MaxTradeRisk
```
---
## 1. Thread Safety — Lock Everything Shared
Every class with shared state must have a lock object: