Skip to main content

WriteNinjaScriptFile

Writes a NinjaScript source file to the NT8 user directory. The file becomes part of the user's NT8 install and will participate in subsequent compiles and Strategy Analyzer runs.

Write Action

Touching the user directory affects every chart and strategy that references the file. Only call this after a green in-memory compile and an explicit user confirmation.

PropertyValue
Required scopemcp:trade
RiskMedium. Modifies the user's NT8 install.
Side effectsWrites a source file to disk.

When an agent should use it

  • Only after CompileNinjaScript(in_memory: true) succeeds.
  • Only after the user has approved the write.

When an agent should not use it

  • As a quick way to save scratch code. Use in-memory compile first.
  • Without overwrite protection if the file already exists.

Parameters

{
"path": "Strategies/MyEmaCross.cs",
"source": "namespace NinjaTrader.NinjaScript.Strategies { ... }",
"overwrite": true
}

Response shape

{
"path": "Strategies/MyEmaCross.cs",
"written": true,
"bytes": 2480
}

Example user prompt

Compile MyEmaCross in memory. If compile succeeds, show me the source you plan
to write and the target path. Wait for me to say "go" before WriteNinjaScriptFile.

Common errors

SymptomLikely causeFix
compile_requiredTried to write without a recent successful compile.Call CompileNinjaScript first.
file_existsoverwrite was false.Either set overwrite: true or choose a new path.

Safe workflow placement

CompileNinjaScript(in_memory: true) → user confirms → WriteNinjaScriptFile

After writing, a follow-up compile against disk is optional but harmless.

Use in AI-generated NinjaScript workflows

  • When the agent should call it: only after a green CompileNinjaScript(in_memory: true) and an explicit user confirmation. This is the door between "trying things" and "the file is on disk."
  • Required scope: mcp:trade.
  • Confirmation required: yes. Always.
  • What the agent should summarize: the path written, the bytes written, and what the agent expects the next step to be (backtest, sweep, review). Should not auto-trigger any next step.
  • Failure mode it helps catch: the wrong file overwriting an existing strategy. The confirmation gate is what prevents it.

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