Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NinjaScript Preflight

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.

CLI report: NinjaScript Preflight flags HIGH issues in an AI-generated strategy

# Same output as above (known-bad fixture)
dotnet run --project src/NinjaScriptPreflight.Cli -- tests/fixtures/AiGeneratedBadStrategy.cs
# or: nspreflight tests/fixtures/AiGeneratedBadStrategy.cs

It 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.

Why this exists

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/CurrentBars guard → "index out-of-range", script disabled;
  • AddDataSeries outside State.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 BarsInProgress dispatch in multi-series scripts → logic runs N times;
  • multi-series indexers (Highs[1]) without AddDataSeries → 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.

Install and run

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.cs

Or after publishing / downloading nspreflight.exe:

nspreflight path/to/MyStrategy.cs

Options:

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

Current release state

  • 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 NSP005 for @-prefixed files
  • License: MIT
  • Public releases: see GitHub Releases for nspreflight.exe

Design

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.

Verification

dotnet test NinjaScriptPreflight.sln
dotnet run --project src/NinjaScriptPreflight.Cli -- tests/fixtures --fail-on none

Important limitations

  • 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.

About

Static pre-load checks for NinjaTrader 8 NinjaScript (catch AI-generated compile-then-break bugs before NT8 does)

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages