Files
nt8-sdk/tools/preflight

preflight

preflight.ps1 is a standalone PowerShell script for morning go/no-go checks before enabling the strategy. It does not import or reference any NinjaTrader assembly.

PowerShell was chosen because this tool is an operator-side environment check: process count, file writability, deployed-source hash verification, and disk-space checks are all native PowerShell tasks and do not need any .NET solution changes.

What It Checks

The script prints PASS or FAIL for:

  1. Exactly one NinjaTrader process running
  2. Log directory writable and no current-day session_YYYYMMDD_*.log already present
  3. Most recent settings_Simple_ORB_NT8_*.txt export has:
    • TestMode=False
    • EnableKillSwitch=True
    • EnableVerboseLogging=True
    • EnableFileLogging=True
    • MinTradeGrade=5
    • MaxDailyTrades=1
  4. Most recent settings export Account and Instrument match the expected arguments
  5. Deployed NT8StrategyBase.cs hash matches the repo copy
  6. All four .cs files copied by deploy-to-nt8.bat (NT8StrategyBase.cs, SimpleORBNT8.cs, BaseNT8StrategyWrapper.cs, SimpleORBNT8Wrapper.cs) match repository SHA-256 hashes, and no unexpected .cs files exist in Strategies
  7. Free disk space in the log directory drive is greater than 1 GB

The folder check allows root-level @/@@ NinjaTrader and operator strategies plus ORBFibPullbackV1.cs and MinimalTestStrategy.cs. It reports discrepancies with file timestamps; unexpected files also report same-named matches under src and any duplicate declared type found in NT8.Strategies.dll or NinjaTrader.Custom.dll. It never deletes deployed files. MinimalTestStrategy.cs remains allow-listed despite the known Verify-Deployment.ps1/batch deploy mismatch (GAP-073).

Every failure prints a specific remedy. The script exits 0 only when every check passes. Any failure returns exit code 1.

Usage

Run with the expected account and instrument:

powershell -ExecutionPolicy Bypass -File .\tools\preflight\preflight.ps1 `
  -ExpectAccount "SimSimple ORB" `
  -ExpectInstrument "NQ SEP26"

Override the log directory if needed:

powershell -ExecutionPolicy Bypass -File .\tools\preflight\preflight.ps1 `
  -ExpectAccount "SimSimple ORB" `
  -ExpectInstrument "NQ SEP26" `
  -LogDirectory "C:\Users\billy\Documents\NinjaTrader 8\log\nt8-sdk"

Override the repo/deployed file paths for validation or alternate installs:

powershell -ExecutionPolicy Bypass -File .\tools\preflight\preflight.ps1 `
  -ExpectAccount "SimSimple ORB" `
  -ExpectInstrument "NQ SEP26" `
  -RepoStrategyBasePath "C:\dev\nt8-sdk\src\NT8.Adapters\Strategies\NT8StrategyBase.cs" `
  -DeployedStrategyBasePath "C:\Users\billy\Documents\NinjaTrader 8\bin\Custom\Strategies\NT8StrategyBase.cs"

Defaults

  • LogDirectory: %USERPROFILE%\Documents\NinjaTrader 8\log\nt8-sdk
  • RepoStrategyBasePath: src\NT8.Adapters\Strategies\NT8StrategyBase.cs relative to the repo root
  • DeployedStrategyBasePath: %USERPROFILE%\Documents\NinjaTrader 8\bin\Custom\Strategies\NT8StrategyBase.cs

Notes

  • The script is read-only except for a temporary write/delete probe file in the log directory used to verify writability.
  • The settings check uses the most recently modified settings_Simple_ORB_NT8_*.txt file in the log directory.
  • The hash check compares SHA-256 of the repo and deployed NT8StrategyBase.cs files.

Gate 3 Freeze Mode

Freeze mode captures Gate Run #3 provenance under docs/gate-runs/gate3/freeze_YYYYMMDD_HHMMSS and writes docs/gate-runs/gate3/baseline.json plus DEC-GATE3-CONFIG.md when all freeze gates pass.

powershell -ExecutionPolicy Bypass -File .\tools\preflight\preflight.ps1 `
  -ExpectAccount "SimSimple ORB" `
  -ExpectInstrument "NQ SEP26" `
  --freeze

PowerShell also accepts -Freeze.

The fixture test for the whole-folder comparison logic can be run directly with:

powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\tools\preflight\tests\strategy-source-verification.tests.ps1

Freeze captures:

  • current settings export
  • ConfigHash and CodeVersion
  • git commit SHA
  • git status --porcelain, which must be clean
  • full test suite result from dotnet test NT8-SDK.sln --configuration Release --verbosity minimal
  • SHA-256 hash of every deployed .cs file in the NT8 Strategies folder
  • tools/configdiff report for the preceding 3 settings exports

If the worktree is dirty, freeze exits non-zero and writes a failed capture folder with git-status-porcelain.txt and FREEZE_FAILED.txt. It does not create or replace baseline.json.

Gate 3 Verify Mode

Verify mode repeats the capture and compares significant fields against docs/gate-runs/gate3/baseline.json. It exits non-zero on any difference.

powershell -ExecutionPolicy Bypass -File .\tools\preflight\preflight.ps1 `
  -ExpectAccount "SimSimple ORB" `
  -ExpectInstrument "NQ SEP26" `
  --verify

PowerShell also accepts -Verify.

Verify compares:

  • settings values
  • ConfigHash
  • CodeVersion
  • git SHA
  • clean git status
  • full-suite pass/fail status
  • configdiff pass/fail status
  • deployed strategy source hashes