NinjaScript > Educational Resources > Tips >

TraceOrders

Print this Topic Previous pageReturn to chapter overviewNext page

TraceOrders is a useful property when debugging the behavior of your orders. With the use of this property, you can track orders placed, amended, and cancelled. The traces displayed in the NinjaScript Output window will provide meaningful information for diagnosis when NinjaTrader ignores, changes or cancels orders when various strategy order methods are called.

 

To enable TraceOrders, add this line into the Initialize() method of your NinjaScript strategy:

TraceOrders      = true;

 

Trace output examples:

10/14/2007 12:25:34 AM Entered internal PlaceOrder() method at 10/14/2007 12:25:34 AM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=676.9 StopPrice=0 SignalName='MyEntry' FromEntrySignal=''

 

This trace is outputted when we place an entry order. It tells us all the pertaining properties of our order as well as the time it was submitted.

10/14/2007 12:25:34 AM Amended matching order: Action=Buy OrderType=Limit Quantity=1 LimitPrice=676.9 StopPrice=0 SignalName=MyEntry' FromEntrySignal=''

 

This trace tells us that a previously submitted order was modified instead of submitting a completely new order.

10/14/2007 12:25:42 AM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=677.4 SignalName=MyStop' FromEntrySignal='MyEntry' Reason='There already is a matching order with same prices and quantity'

 

This trace provides the reason why our stop-loss order was ignored.

10/14/2007 12:26:02 AM Cancelled pending exit order, since associated position is closed: Order='a4906973e61847489885140fa29019d4/Sim101' Name='MyStop' State=Accepted Instrument='ER2 12-07' Action=Sell Limit price=0 Stop price=677.4 Quantity=1 Strategy='SampleOnOrderUpdate' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='a4906973e61847489885140fa29019d4' Gtd='12/1/2099 12:00:00 AM'

 

This trace tells us that our stop-loss order was cancelled because its corresponding position was already closed by another order.

 

These examples illustrate the most common traces you will run across. They are mostly useful in determining the reason your orders are not submitted or cancelled. TraceOrders will only show you what is happening under the hood when you submit orders, but it will not tell you what happens after the order is submitted. To determine the behavior of your orders after submission you will need to look into your NinjaTrader trace logs. You can view those either through the "Log" tab on the "Control Center" or from the trace folder in My Documents\NinjaTrader 7\trace\.

 

For more information on how to debug your NinjaScript please review the Debugging tip.