The Complete Guide to NinjaTrader Commands

This guide aims to provide a comprehensive breakdown of NinjaTrader commands and CrossTrade enhancements that streamline automated trading through TradingView webhooks.

NinjaTrader commands guide with checklist icon on puzzle background.
Complete Guide to NinjaTrader Commands: Master Every Function.

NinjaTrader is a highly flexible trading platform that enables users to automate trading strategies and manage orders programmatically. By leveraging NinjaTrader’s Automated Trading Interface (ATI), traders can create sophisticated systems for enhanced trading execution.

This guide aims to provide a comprehensive breakdown of NinjaTrader commands and CrossTrade enhancements that make trading even more streamlined. Whether you're running long-term strategies or scalping index futures, CrossTrade can help you do it.

💡
This guide frequently links to our Help Docs, which offer a more comprehensive understanding of our entire platform and tool set.

Prerequisite: Setting up NinjaTrader 8

Before using NinjaTrader with CrossTrade, ensure that NinjaTrader 8 is installed and that you have enabled the Automated Trading Interface (ATI) in the platform. This can be done by going to: Tools > Options > Automated Trading Interface

Once activated, you are ready to start integrating these commands to manage your trades automatically.

Get NinjaTrader 8 here


NinjaTrader Command Overview

NinjaTrader commands allow you to control every aspect of your trading from order placement to managing positions. Each command takes various parameters that dictate the specific actions to be taken. Below, we break down the most commonly used commands and their parameters.

At CrossTrade we try to mimic, as closely as possible, the available order instructions natively available to NT8's ATI. As of this writing, any command you could craft for ATI is now remotely available through CrossTrade.

Reference NinjaTrader's Help Documentation here


This article assumes that you already have baseline knowledge of setting up TradingView webhooks, and each section will discuss how to craft the "alert message" of the webhook. If you are unsure how to setup your TV webhooks, follow along with this setup guide before continuing.

Basic Commands

  1. The PLACE command is used to submit a new order to NinjaTrader. You can specify the account, instrument, order type, and other essential trade details like quantity and time-in-force (TIF).
  2. The CLOSE command (CLOSEPOSITION) will close any active positions for the specified account and instrument, cancelling any working orders in the process.
    • Additionally, the CLOSESTRATEGY command will close an ATM Strategy and requires only the strategy ID.
  1. The REVERSE POSITION command reverses your current position by closing it and immediately placing an opposite order. It’s ideal for flipping your trade direction quickly.
    • Additionally, we developed the REVERSE command, which is a true inversion of an existing position
  1. The FLATTEN EVERYTHING command will close all active positions and cancel all open orders across all accounts and broker connections. This is considered the nuclear option.
    • Additionally, we developed the FLATTEN command, which provides different ways to flatten specific positions and accounts.
  1. The CANCEL command will cancel an order and requires an order ID vale and an optional strategy ID value.
    • Additionally, we developed the CANCELALLORDERS command, which will cancel all active orders across all accounts and brokerage connections. The CANCELREPLACE command is a combination of CANCEL and PLACE.
  1. The CHANGE command will change the parameters of an order and requires an order ID value, optional price and quantity values and an option strategy ID value.

Place Order (PLACE)

This payload will trigger a simple market order for BUY or SELL actions that will remain in-force for the rest of the trading day.  

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
💡
Be aware that if you send a BUY order and then a SELL order using the same quantity, the sell order will offset the buy position. This scenario does not create a net short position.

If you want to close an existing position before opening a new position, include "flatten_first=true;" inside your message. 

Close Position (CLOSEPOSITION)

This command will close a position and requires an account name value and an instrument name value.

key=your-secret-key;
command=CLOSEPOSITION;
account=sim101;
instrument=ES 06-25;
💡
The instrument name value is the name of the NinjaTrader instrument including the exchange name. For equities, the symbol is sufficient. This command will cancel any working orders and flatten the position.

Reverse Position (REVERSEPOSITION)

This command will close the current position and place an order in the opposite direction. The field requirements are identical to the PLACE command.

key=your-secret-key;
command=REVERSEPOSITION;
account=sim101;
instrument=ES 06-25;
action=SELL;
qty=1;
order_type=MARKET;
tif=DAY;
💡
When reversing a position with an ATM strategy, you'll want to ensure that the action is also the opposite of the existing position you intend to reverse.

Flatten Everything (FLATTENEVERYTHING)

This command will cancel all active orders and flatten all positions across all accounts and broker connections.

key=your-secret-key;
command=FLATTENEVERYTHING;

Cancel (CANCEL or CANCELALLORDERS)

This command will cancel and order and requires an order ID and an optional strategy ID value.

key=your-secret-key;
command=CANCEL
order_id=your-order-ID;
strategy_id=your-strategy-id; (optional)

Change (CHANGE)

This command will change the parameters of an order and requires an order ID value, option price and quantity values and an optional ID value.

key=your-secret-key;
command=CHANGE;
qty=1; (optional)
limit_price=XXX; (optional)
stop_price=XXX; (optional)
order_id=your-order-id;
strategy_id=your-strategy-id; (optional)

Using Different Order Types

    • Market: A simple command to place a BUY or SELL market order. It executes immediately at the current market price.
    • Limit: To buy or sell at a specified price. If the price is above or below the current market, the order may execute immediately.
    • Stop: This command triggers a market or limit order when a specified stop price is reached. The stop_price parameter is crucial here.

Buy or Sell (Market Orders)

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;

Buy or Sell Limit Orders

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=LIMIT;
limit_price=4500;
tif=DAY;
💡
If you place a Buy limit order above the current price, or a Sell limit order below, it will be executed immediately as you're crossing the spread.

Stop Market and Stop Limit Orders

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=STOPMARKET;
stop_price=4600;
tif=DAY;
💡
You must use the stop_price command and not the limit_price command when submitting Stop Market or Stop Limit order types

Using ATM Strategy Templates

This payload will trigger a simple market order for BUY or SELL actions that will use an ATM strategy template and remain in-force for the rest of the trading day.  

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
strategy=crosstrade;
💡
Similar to the offsetting scenario when sending a Sell after a Buy, when using an ATM strategy, this will create orphaned Stops and Target orders as those are not cancelled by default. You must send a CLOSEPOSITION or REVERSEPOSITION command before the next directional trade to avoid this.

The quantity you set inside of your CrossTrade alert will supersede your default ATM quantity

CrossTrade Enhancements

CrossTrade has added several enhancements to make trading with NinjaTrader even more efficient and customizable.

  • Multi-Account Placement: Separate the account names with commas and send one alert to as many accounts as you want.
  • Flatten First: This option ensures that any open positions are flattened before submitting a new buy/sell order. This saves time and ensures no overlapping positions when switching trades.
  • Require Market Positions: Block alerts where the market position (long, short, flat) of the position doesn't match.
  • Max Positions: Only allow alerts where an opening order won't exceed the max positions allowed in account.
  • Take Profit and Stop Loss: Define levels in your orders for precise risk management. These values are numeric and create automatic opposing orders.
  • Percentage and Tick Price Levels: Specify any price level as a number price or, alternatively, as a % of the underlying price or number of ticks from the underlying price.
  • Limit Order Timeouts: Cancel a limit order after X minutes if not filled
  • Trading Window: Set an alert-level trading window (start, end, and closing only times) in addition to or instead of the Global trading window on the XT Control Panel.
  • Bypass Trade Windows: Override and bypass all Global, Alert & Account-level trade windows
  • Delay Timer: Specify a delay timer for the alert up to 60 seconds.
  • Rate Limiting: Set a rate limit to prevent too many alerts from executing in a short period. You can specify an ID to group related requests and set how frequently they can be processed.
  • Alert Commenting: Use comments in your alerts by placing // at the beginning of any line. Comments are ignored during execution, making it easy to annotate or provide context without disrupting the command flow.
  • Kill Switch: Turn the Master Kill Switch on/off through webhooks
  • Notes: Write notes inside an alert that will show on Activity and Alert History logs

Multi-Account Placement

Send an order alert to as many NinjaTrader accounts as you want with no limitations on the account type. Why pay for trade copiers or replicators when you can use CrossTrade to mirror orders to as many accounts as you want without limit?

key=your-secret-key;
command=PLACE;
account=sim101,sim102,sim103;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
💡
Separate each account name with a comma and we'll generate an identical order for each account.

Learn more

Flatten First

When enabled, any existing position in the same instrument will be flattened before the buy/sell order is created.

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
flatten_first=true;
💡
This feature was inspired by you, the traders. Many of you reached out to us and said, "If only we could open or reverse without having to use multiple alerts!"

Learn more

Require Market Position

The flag require_market_position is available to any command with both an account and instrument field. It blocks and prevents the signal from going through unless the NT8 market position matches your command.

To check for the "long or flat" conditions, separate the values with a comma. CSV values represent an "or" condition between them: "flat or long", "long or short", etc. They can be in any order: "flat,long", "long,flat", etc.

An example command would be:

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
require_market_position=long,flat;
💡
Require Market Position is a versatile way for you to block signals unless the underlying account state matches. Be sure to check out the Help Docs article for other use cases.

Take Profit and Stop Loss

Adding take profit and stop loss levels to an alert is very simple and is only available as part of the PLACE order command. Both fields accept numeric values only that represent price level triggers for the order in the underlying.

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
take_profit=4700;
stop_loss=4400;
💡
When CrossTrade receives a request for either TAKE_PROFIT or STOP_LOSS inside of a place order message, it creates an opposing order (buy becomes sell and vice versa, same quantity, etc.). TAKE_PROFIT becomes a buy or sell limit order to guarantee the profit target is hit, while STOP_LOSS becomes a buy or sell stop market order. Both orders are entered as GTC (Good-til-Canceled).

Learn more

Rate Limiting

To use rate limiting, you simply have to provide a rate_limit and id identifier field to any alert message to track the message type. In this example, we set a rate_limit=1 and id=mystrategy.

key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
rate_limit=1;
id=mystrategy;
💡
By default, if the rate limit is a single number, it defines the number of requests allowed through CrossTrade every one minute for that id. So if 2 alerts show up within a few milliseconds of each other, the first one with that id will be accepted, and the second one will be blocked.

Learn more

Commenting

Any line start with a double forward slash (//) will be stripped out prior to ingestion at CrossTrade. This means that you can add as many comments as needed without affecting the execution of your alert messages.

//This is a comment line where I leave notes about my strategy
key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
💡
The use case here is allowing the ability for multiple different tools to interpret the alert message at the same time.

Learn more

Final Thoughts

With this detailed guide, you now have a comprehensive understanding of the core NinjaTrader commands and how CrossTrade’s enhancements can make your automated trading smoother and more efficient. Whether you're placing market orders, managing positions, or implementing advanced risk controls, NinjaTrader combined with CrossTrade ensures your trades are executed exactly as you want.