Skip to main content

How to Use Claude Code with NinjaTrader 8 and CrossTrade MCP

Claude Desktop is the right environment for chat-style account inspection. Claude Code is the right environment for NinjaScript work. The CLI can edit local files and call CrossTrade MCP tools in the same conversation, which makes the compile loop converge fast.

Why Claude Code is useful for NinjaScript

Claude Code can read and write local files, run shell commands, and call MCP tools in one session. That combination is what turns a brittle "paste compile errors back to the chat" workflow into a real compile loop. CrossTrade MCP adds the part Claude Code cannot do on its own: it lets the agent look at your actual NT8 install instead of guessing.

What CrossTrade MCP adds beyond code generation

CapabilityTool
Look up the real NinjaScript symbols available in your installGetNinjaScriptHelp, SearchNinjaScriptSymbols, LookupNinjaScriptSymbol
Compile against the running NT8 AppDomain without disk writesCompileNinjaScript(in_memory: true)
Write the source file once compile is greenWriteNinjaScriptFile
Run NT8's actual Strategy Analyzer engineRunStrategyBacktest
Verify a deployed strategy is actually tradingGetDeployedStrategyState

Prerequisites

RequirementDetail
CrossTrade subscriptionElite
CrossTrade Add-Onv1.13.0 or higher
NinjaTrader 8Running, broker connected
Claude CodeInstalled CLI
Scopemcp:trade for compile/write/backtest
AccountSim101 first
Sim101 only for first runs

The compile loop needs mcp:trade. Use Sim101 as the default account. Do not run deployment or order placement on a funded account during initial setup.

Step 1: Add the CrossTrade MCP server

In your terminal:

claude mcp add --transport http crosstrade https://app.crosstrade.io/v1/api/mcp

On the first tool call, Claude Code prints an OAuth URL. Open it in a browser, approve mcp:trade, and return to the terminal. The token is stored in Claude Code's keychain.

Step 2: Verify read-only environment calls

Even with mcp:trade, start by reading state:

Call GetMcpCapabilities and McpSelfTest. Then ListAccounts and GetConnections.
Tell me the add-on version, NT8 version, backtest engine availability, and which
accounts are connected.

If anything is missing, fix it before writing code.

Step 3: Ask Claude Code to inspect NinjaScript help

Before generating a strategy, ground the model in your install:

For an MES 5-minute EMA crossover strategy with an ATR-based trailing stop,
call GetNinjaScriptHelp on EMA, ATR, CrossAbove, and SetTrailStop. Restate the
overloads you intend to use before drafting any code.

Claude should list the chosen overloads and any alternatives it considered.

Step 4: Generate a simple strategy

Draft a NinjaScript strategy called SampleEmaCross for Sim101. Long when 9-EMA
crosses above 21-EMA. ATR-based trailing stop, multiplier 2.0. One contract.
Max two trades per session. Time filter 09:30 to 11:00 ET. Do not compile yet.
Show me the source.

Read the source. Look for obvious issues. Push back on anything that doesn't match the spec.

Step 5: Compile and repair errors

CompileNinjaScript(in_memory: true). For each error, explain it in plain English.
For every unresolved identifier, LookupNinjaScriptSymbol and rewrite the offending
line. Recompile until green. Do not write the file yet.

Typical first compile produces 1-3 errors. The agent should resolve them in two or three iterations.

Step 6: Backtest in Strategy Analyzer

After a green compile, ask Claude Code to write the file with explicit confirmation, then backtest:

After I confirm, WriteNinjaScriptFile. Then RunStrategyBacktest on Sim101 over
the last 30 trading days, 5-minute bars, commission $1.27 per round-trip,
slippage 1 tick. Show the metrics block.

When the metrics return, read both the metrics and (when feasible) the trade list. Confirm that entries and exits behave the way the spec described.

Step 7: Interpret results

The metrics block alone is not enough. Ask for an honest review:

Apply these gates: profit factor above 1.25, max drawdown below $500, trade count
above 40. Report pass or fail for each. Then list five reasons this generated
strategy should not go to a live or funded account. Be specific.

If the gates fail, iterate. If they pass, the strategy is ready for further validation on Sim101 over several sessions, not for live deployment.

Step 8: Save or discard the strategy

If the strategy looks promising, commit the file to your local workflow. Claude Code can run git commands. If the strategy is unviable, instruct Claude Code to remove the file and document what you learned.

If we keep the strategy, leave the file and add a note in a CHANGELOG.md. If we
discard it, DeleteCompiledSnippet for the in-memory class and remove the file.

Safety and funded-account notes

  • The OAuth scope is mcp:trade. The OAuth scope alone does not protect a funded account; only your prompt does.
  • Do not let Claude Code deploy strategies to a funded account in this tutorial. Use Sim101 only.
  • For funded accounts, verify the firm's automation policy. Apex prohibits automation; Topstep permits with caveats; others vary.

Troubleshooting

SymptomLikely causeFix
OAuth URL never opensTerminal capturing the URL incorrectlyCopy the URL manually from the output
Compile fails on the same identifier repeatedlyModel not calling LookupNinjaScriptSymbolForce a SearchNinjaScriptSymbols on a synonym
403 insufficient_scopeToken is mcp:readReauthorize at mcp:trade
Backtest stuck on runningNT8 UI blocked or large date rangeOpen NT8, dismiss any modal, or shorten the range

FAQ

Why Claude Code instead of Claude Desktop for NinjaScript?

Claude Code can edit your local files and run git commands in the same session that calls MCP tools. The compile loop is faster end to end.

Do I need C# experience?

Helpful but not required. The agent does the writing. You provide the spec and read the diff.

Can Claude Code deploy strategies?

With mcp:trade and explicit confirmation in the prompt, yes. This tutorial stops short of deployment. See Build Your First AI Trading Agent for the deploy gate.