5.1 KiB
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:
- Exactly one
NinjaTraderprocess running - Log directory writable and no current-day
session_YYYYMMDD_*.logalready present - Most recent
settings_Simple_ORB_NT8_*.txtexport has:TestMode=FalseEnableKillSwitch=TrueEnableVerboseLogging=TrueEnableFileLogging=TrueMinTradeGrade=5MaxDailyTrades=1
- Most recent settings export
AccountandInstrumentmatch the expected arguments - Deployed
NT8StrategyBase.cshash matches the repo copy - All four
.csfiles copied bydeploy-to-nt8.bat(NT8StrategyBase.cs,SimpleORBNT8.cs,BaseNT8StrategyWrapper.cs,SimpleORBNT8Wrapper.cs) match repository SHA-256 hashes, and no unexpected.csfiles exist inStrategies - 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-sdkRepoStrategyBasePath:src\NT8.Adapters\Strategies\NT8StrategyBase.csrelative to the repo rootDeployedStrategyBasePath:%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_*.txtfile in the log directory. - The hash check compares SHA-256 of the repo and deployed
NT8StrategyBase.csfiles.
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
ConfigHashandCodeVersion- 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
.csfile in the NT8Strategiesfolder tools/configdiffreport 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
ConfigHashCodeVersion- git SHA
- clean git status
- full-suite pass/fail status
- configdiff pass/fail status
- deployed strategy source hashes