Static pre-load checks for NinjaTrader 8 NinjaScript. Point it at a .cs
indicator or strategy — including AI-generated ones — and get a line-by-line
report of the defects that most often break the platform compile, silently
fail to load, or disable the script on the first bars.
# Same output as above (known-bad fixture)
dotnet run --project src/NinjaScriptPreflight.Cli -- tests/fixtures/AiGeneratedBadStrategy.cs
# or: nspreflight tests/fixtures/AiGeneratedBadStrategy.csIt is intentionally narrow: it reads source code and prints findings. It never executes the script, never touches market data or accounts, and produces no trade signals.
The same failure loop appears in NinjaTrader forums week after week: someone generates a script with ChatGPT/Claude/Grok, it compiles-then-breaks (or never compiles), and official support replies that debugging AI-generated code is outside their support model. The highest-frequency root causes are boringly consistent and statically detectable:
- missing
CurrentBar/CurrentBarsguard → "index out-of-range", script disabled; AddDataSeriesoutsideState.Configure→ throws on load, strategy "missing";- wrong namespace or invented base type → platform never sees the script;
- NinjaTrader 7 API residue (
Initialize(),CalculateOnBarClose,DrawLine(...)) → dead code or compile errors; - no
BarsInProgressdispatch in multi-series scripts → logic runs N times; - multi-series indexers (
Highs[1]) withoutAddDataSeries→ runtime disable on enable; - managed/unmanaged order API mixing → runtime rejection.
Preflight encodes 21 such checks. The full catalog with exact semantics is in
SPEC.md.
Prerequisite: .NET 8 SDK (any OS), or use the published self-contained Windows binary from Releases (no runtime needed).
From this directory:
dotnet run --project src/NinjaScriptPreflight.Cli -- path/to/MyStrategy.csOr after publishing / downloading nspreflight.exe:
nspreflight path/to/MyStrategy.csOptions:
nspreflight <file-or-directory>... [--json] [--fail-on high|medium|low|info|none]
--json machine-readable output (rule id, severity, line, message, fix)
--fail-on SEV exit 1 when a finding at or above SEV exists (default: high)
Directories are scanned recursively for .cs files, so you can audit an
entire bin/Custom/Strategies folder at once. Exit codes (0 = clean,
1 = findings, 2 = usage error) make it usable as a pre-commit or CI gate.
Publish a standalone Windows binary:
dotnet publish src/NinjaScriptPreflight.Cli -c Release -r win-x64 \
--self-contained -p:PublishSingleFile=true -o dist- Core build and 72 automated tests: pass
- Known-bad fixture (
tests/fixtures/AiGeneratedBadStrategy.cs) reports the documented rule set; known-clean fixture reports zero findings: pass - Dogfooded on sample NinjaScript indicators/strategies: zero High findings
on stock NT8 samples aside from expected Low
NSP005for@-prefixed files - License: MIT
- Public releases: see GitHub Releases for
nspreflight.exe
src/NinjaScriptPreflight.Core/ Roslyn syntax analysis + 21 rules (no platform DLLs)
src/NinjaScriptPreflight.Cli/ argument parsing, text/JSON reports, exit codes
tests/NinjaScriptPreflight.Core.Tests/ per-rule positive/negative cases + fixtures
tests/fixtures/ known-bad and known-clean NinjaScript samples
There is no NinjaTrader/ATAS shell: the tool analyzes scripts instead of
running inside a platform, so every layer is verifiable on any OS with
dotnet build && dotnet test. Rules operate on a pre-digested ScriptModel
(script class, lifecycle state regions, guard shapes, series variables), so
each rule stays a small, independently tested pattern match.
dotnet test NinjaScriptPreflight.sln
dotnet run --project src/NinjaScriptPreflight.Cli -- tests/fixtures --fail-on none- Static, syntax-level heuristics. Always verify findings in the NinjaScript Editor and validate behavior in Market Replay before trusting a script.
- A clean report does not mean the script is correct, safe, or profitable — only that none of the 21 known defect patterns were detected.
- Helper-method indirection and some semantic-level hallucinations are out of scope for v0.1 (the platform compiler catches many of the latter).
Not affiliated with NinjaTrader. NinjaTrader® and NinjaScript® are trademarks of NinjaTrader, LLC, used here only to describe compatibility.
For educational/analytical purposes, not financial advice.
