Examples & Use Cases
Example Alerts & Order Behavior
Now that you're familiar with NinjaTrader's various command functions, let's roll through some example alerts and how they behave on NinjaTrader. Buy or Sell
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;
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. More Info on Flatten_First.
Buy or Sell with ATM Strategy
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;
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.
Buy or Sell Limit Orders
This payload will trigger a simple limit order for BUY or SELL actions that will use the specified limit price.
key=your-secret-key; command=PLACE; account=sim101; instrument=NQ 12-24; action=BUY; qty=1; order_type=LIMIT; limit_price=X (price below market) 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
This payload will trigger a Stop Market or Stop limit order for BUY or SELL actions that will use the specified stop price.
key=your-secret-key; command=PLACE; account=sim101; instrument=NQ 12-24; action=BUY; qty=1; order_type=STOPMARKET stop_price=X (price above market) TIF=DAY;
You must use the stop_price command and not the limit_price command when submitting Stop Market or Stop Limit order types.
Close Position
This command will close a position and requires an account name value and an instrument name value. 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.
key=your-secret-key; command=CLOSEPOSITION; account=sim101; instrument=NQ 12-24;
Flatten Everything
This command will cancel all active orders and flatten all positions across all accounts and broker connections.
key=your-secret-key; command=FLATTENEVERYTHING;
Reverse Position
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=BUY; qty=1; order_type=MARKET; TIF=DAY; strategy=crosstrade;
When reversing a position with an ATM strategy, you'll want to ensure that a position already exists in the underlying instrument and the action is also the opposite of the existing position you intend to reverse.
Last updated