Skip to main content

CompileNinjaScript

Compiles NinjaScript against the running NT8 AppDomain. In in_memory mode the result lives only in memory, which makes the compile loop safe to iterate on without touching disk.

PropertyValue
Required scopemcp:trade
RiskMedium. Does not deploy or trade, but writing to disk later is downstream.
Side effectsIn in_memory: true, none on disk. In in_memory: false, writes to the NT8 user directory.

When an agent should use it

  • After authoring a NinjaScript draft.
  • Iteratively during compile-error repair.
  • Before any WriteNinjaScriptFile.

When an agent should not use it

  • As a way to "deploy" a strategy. Compilation alone does not start trading.

Parameters

{
"class_name": "MyEmaCross",
"source": "namespace NinjaTrader.NinjaScript.Strategies { ... }",
"in_memory": true
}

Response shape

Successful:

{
"compile_id": "c-1234",
"success": true,
"class_name": "MyEmaCross",
"warnings": []
}

Failed:

{
"compile_id": "c-1234",
"success": false,
"errors": [
{"file": "MyEmaCross.cs", "line": 42, "message": "The name 'EmaCross' does not exist..."}
]
}

Example user prompt

Compile this MyEmaCross strategy in memory. If it fails, look up any unresolved
symbols with LookupNinjaScriptSymbol and SearchNinjaScriptSymbols, repair, and
recompile. Do not write the file until compile is green.

Common errors

SymptomLikely causeFix
CS0103 unknown nameThe model invented an API.Resolve with LookupNinjaScriptSymbol.
CS1503 type mismatchWrong overload chosen.Use GetNinjaScriptHelp for the signature.
addon_disconnectedNT8 not running.Open NT8.

Safe workflow placement

GetNinjaScriptHelp / Search / Lookup → CompileNinjaScript(in_memory: true)
→ on failure: repair → recompile → on success: WriteNinjaScriptFile

Use in AI-generated NinjaScript workflows

  • When the agent should call it: after every draft, and after every repair. The compile loop is the central feedback channel for vibe coded NinjaScript.
  • Required scope: mcp:trade.
  • Confirmation required: no for in_memory: true compiles, because they do not touch disk. Yes if in_memory: false is used outside the standard compile loop.
  • What the agent should summarize: success or failure, the full list of diagnostics in plain English, and the plan to fix each one.
  • Failure mode it helps catch: any draft that does not actually compile in your install. The agent cannot fool itself once it has compile output.

For the broader vibe coding workflow, see NinjaScript AI Workflow.