MCP Trading with AI Agents
This is the operational manual for running an AI trading agent against your real NinjaTrader 8. CrossTrade MCP gives Claude, ChatGPT, Cursor, and any Model Context Protocol client a typed tool surface that covers the entire research-to-live loop: inspect account state, pull bars, write NinjaScript, compile it against your install, backtest through NT8's actual Strategy Analyzer engine, optimize with parameter sweeps, deploy the winner, and monitor the deployment until you stop it.
The phrase "AI trading agent" is doing real work here. Agents are not chatbots that talk about trading; they are programs that call tools, observe results, and make the next decision. This Learn section is about what to ask an agent so it stays inside guardrails. The API docs explain the transport and exact tool shapes. The prompts here are designed to be copy-paste-and-adapt for a real trading day.
The hosted MCP server requires Elite and CrossTrade Add-On v1.13.0 or higher. Client setup is covered in AI-Assisted Development. The technical MCP reference starts at MCP Trading API.
The agent loop, in one sentence
Inspect → write → compile → backtest → optimize → deploy → verify → monitor → close. Every arrow is one or more MCP tool calls. Every arrow is a place an agent can be wrong, so every prompt below builds a checkpoint.
Start with a safety frame
Before any trading session, give your agent boundaries. The goal is to make the model prove it knows the account, instrument, position, orders, and risk budget before it does anything with side effects.
You are connected to CrossTrade MCP as a trading agent. Treat this as a live trading session, not a chat demo.
Use Sim101 unless I explicitly name another account. Before any order, flatten, strategy deployment, or file write, state the exact account, instrument, quantity, current position, working orders, and why the action is allowed. If any data is missing or the add-on is disconnected, stop and tell me what is missing.
Stricter version for prop firm or live-account work:
I am trading a funded evaluation. Do not place orders or deploy a strategy unless the account, remaining daily loss room, open risk, and working orders are checked first. If open risk plus proposed risk could violate the daily loss limit, refuse the action and suggest a smaller or no-trade alternative.
What the agent can do
| Goal | Use these prompts | Related docs |
|---|---|---|
| Inspect account state and open risk | Account and Risk Prompts | Core MCP Tools |
| Research a market or strategy idea | Market Research Prompts | Backtesting Best Practices |
| Write, compile, backtest, optimize, and deploy NinjaScript | NinjaScript and Strategy Prompts | NinjaScript and Strategies, Backtesting and Optimization |
| Operate charts, alerts, workspaces, reconnect verification, and dangerous-action gates | Operations and Safety Prompts | MCP Workflows and Safety |
A realistic full-session agent prompt
This is the kind of prompt MCP was built for. It scopes the account, demands a risk check, names a research target, sets quantitative deployment gates, and forces a final confirmation before anything writes to disk or runs live.
I'm in an Apex $50k evaluation on account APEX1234 with about $200 of daily loss room left. Defensive ideas only.
1. Inspect the account first: positions, working orders, executions, account summary, and watermarks. If current risk is already too high, stop.
2. If the account is safe, research a one-contract MES morning scalper for the current front month. Constraints: time filter, no averaging down, ATR-based stop, target no larger than 1.5R, max two trades per session, hard daily lockout after two losses or $150 down.
3. Write the NinjaScript. Compile in memory first; if it fails, fix and recompile. Only write the file when compile is green.
4. Backtest on the last 60 days of MES 5-minute bars. Gate: profit factor above 1.25, max drawdown below $350, at least 40 trades. If any gate fails, show me the failed metric and stop.
5. If all gates pass, sweep the stop multiplier and target ratio with RunStrategyBacktest optimization. Show me the top three results. Re-run a full single backtest on the best parameter set so I see every trade.
6. Ask me for final confirmation before DeployStrategy. After deploy, call GetDeployedStrategyState and confirm is_trading.
7. EmitMcpAlert with subtype deployment_started and the strategy summary so I get a notification.
This is one prompt. The agent will issue dozens of tool calls. Every checkpoint is a place where you can interrupt.
The full idea-to-live loop, as MCP calls
GetMcpCapabilities // confirm backtest_engine.available
McpSelfTest
ListAccounts
GetConnections
GetAccountSummary / GetWatermarks // current risk
ListPositions / ListOrders // current exposure
GetQuote / MarketInfo / GetBars // market state
GetNinjaScriptHelp / SearchNinjaScriptSymbols // teach the model the local NT8 surface
LookupNinjaScriptSymbol
CompileNinjaScript(in_memory: true) // syntax check, no disk write
WriteNinjaScriptFile(overwrite: true) // only after green compile
RunStrategyBacktest // single backtest, gate against thresholds
RunStrategyBacktest(optimization: {...}) // optional parameter sweep
GetMcpJob(job_id) // poll until completed
DeployStrategy(parameters: best.parameter_values)
GetDeployedStrategyState(deployment_id) // verify is_trading
EmitMcpAlert(alert_subtype: "deployment_started")
// ...trade...
StopStrategy(deployment_id, remove: true)
RemoveAlert(alert_id) // session cleanup
Every step is documented. The agent runs the sequence; you approve the gates.
Learn the risk concepts first
MCP does not make a weak trading idea safe. It makes the workflow faster and more inspectable. If you are new to the risk side, read these before turning an agent loose:
- Daily Loss Limits
- Position Sizing
- Max Drawdown
- Sharpe vs Sortino
- ES vs MES
- Backtesting Best Practices