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;
[FONT="] 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=''[/FONT]
[FONT="] 10/14/2007 12:25:34 AM Amended matching order: Action=Buy OrderType=Limit Quantity=1 LimitPrice=676.9 StopPrice=0 SignalName=MyEntry' FromEntrySignal=''[/FONT]
[FONT="] 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'[/FONT]
[FONT="] 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'[/FONT]
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.
Comment