Skip to main content

How to Flatten NinjaTrader Positions with an AI Agent

Flatten realizes P&L immediately. It is one of the most destructive write actions an agent can take. This tutorial walks the confirmation-gated pattern, the difference between single-instrument and account-wide flatten, and the verification step.

Direct answer

  1. Authenticate with mcp:trade.
  2. Ask the agent to list positions and propose a flatten plan.
  3. Review the plan.
  4. Confirm.
  5. The agent calls Flatten (single instrument) or FlattenEverything (account-wide) only after your confirmation.
  6. The agent re-lists positions to verify the account is actually flat.

Prerequisites

RequirementDetail
CrossTrade subscriptionElite
CrossTrade Add-Onv1.13.0 or higher
MCP clientAny client supporting mcp:trade
Scopemcp:trade
AccountSim101 for first tests
Flatten realizes P&L

Flatten converts open paper losses into realized losses. On a funded account it can lock the day or violate trailing drawdown immediately. Treat every flatten as a deliberate decision, never as a default reaction to discomfort.

Step 1: Authenticate with mcp:trade

See Use mcp:read vs mcp:trade.

Step 2: Propose a flatten plan

For a single instrument:

ListPositions for <account>. Propose a Flatten plan for <instrument>. Tell me
the current side, quantity, average price, and unrealized P&L. Do not flatten
yet.

For everything in the account:

ListPositions for <account>. Propose a FlattenEverything plan. List every
position that will be closed with current quantities and unrealized P&L. Do
not flatten yet.

Step 3: Review

Read the plan. Make sure:

  • The account is the one you intend.
  • The instrument list is what you expect.
  • The quantities match positions you actually want to close.

Step 4: Confirm

Flatten only <instrument> on <account>. Wait for "go" before calling.

Or:

FlattenEverything on <account>. Wait for "go" before calling.

The agent restates and pauses. Type "go".

Step 5: Verify

After the flatten, ListPositions for <account>. Confirm everything is flat. If
anything is still open, tell me.

FlattenEverything does not always close instantly; a fast market or partial-fill scenario can leave residual quantity. The verification step is non-optional.

Emergency flatten

Even an emergency should not be silent. Use this prompt:

Emergency: flatten <instrument> on <account> as soon as possible. Restate the
action first; I will confirm with "go" within 10 seconds.

The pause is brief but real. A "default to yes" pattern is a recipe for closing the wrong position.

Funded futures notes

  • A flatten on a funded account is the agent acting on your behalf. Some firms count this as automation regardless of intent. Verify the firm's automation policy.
  • Some firms have EOD-flatten requirements; the agent can remind you and propose, but you should still confirm.
  • Trailing-drawdown accounts get hit hard by a flatten at the wrong moment. The agent should report remaining drawdown room as part of the proposal.

Troubleshooting

SymptomFix
403 insufficient_scopeReauthorize at mcp:trade
account_disconnectedReconnect the account in NT8
Residual position after flattenRe-list positions; manual cleanup may be needed