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 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.
CrossTrade is new software technology that connects TradingView to NinjaTrader for fully automated trading through webhook alerts.
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.
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.
NinjaTrader Command Basics
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.
Command Overview
- 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).
- 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.
- The REVERSE command reverses your current position by closing it and immediately placing an opposite order. It’s ideal for flipping your trade direction quickly.
- The FLATTEN command will close all active positions and cancel all open orders across all accounts and broker connections.
- The CANCEL command will cancel an order and requires an order ID vale and an optional strategy ID value. Additionally, the CANCELALLORDERS command cancel all active orders across all accounts and brokerage connections.
- 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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
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=NQ 12-24;
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=NQ 12-24;
action=SELL;
qty=1;
order_type=MARKET;
tif=DAY;
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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
Buy or Sell Limit Orders
key=your-secret-key;
command=PLACE;
account=sim101;
instrument=NQ 12-24;
action=BUY;
qty=1;
order_type=LIMIT;
limit_price=4500;
tif=DAY;
Stop Market and Stop Limit Orders
key=your-secret-key;
command=PLACE;
account=sim101;
instrument=NQ 12-24;
action=BUY;
qty=1;
order_type=STOPMARKET;
stop_price=4600;
tif=DAY;
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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
strategy=crosstrade;
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.
- 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.
- Take Profit and Stop Loss: Define levels in your orders for precise risk management. These values are numeric and create automatic opposing orders.
- Multi-Account Placement: Separate the account names with commas and send one alert to as many accounts as you want.
- 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.
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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
flatten_first=true;
Learn more
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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
take_profit=4700;
stop_loss=4400;
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
Self 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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
rate_limit=1;
id=mystrategy;
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
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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
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=NQ 12-24;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
Learn more
Frequently Asked Questions (FAQ)
What values are valid for the {action, account, strategy, etc.} field?
For a complete list of acceptable values for each field in the command messages above, please review the Available Parameters and Valid Values section of this article.
Other services make me pay per alert message, is CrossTrade really unlimited?
When we say unlimited, we mean unlimited. Send as many alerts as you want from TradingView. We think the idea of paying per alert is ridiculous.
Can I trade prop accounts through CrossTrade?
Yes, you certainly can! We've even compiled a list of all the best prop deals and coupon codes currently available on our Get Funded page.
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.