• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TraceOrders

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    TraceOrders

    Applies to: NinjaTrader 7

    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:
    Code:
    TraceOrders      = true;
    Trace output examples:
    Code:
     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.

    Code:
     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.

    Code:
     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.

    Code:
     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.
    Last edited by NinjaTrader_Jesse; 06-03-2015, 12:17 PM.
    JoshNinjaTrader Customer Service

    #2
    Applies to: NinjaTrader 8

    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 or if used, in the OnOrderTrace Override in the script where this was set. This 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 OnStateChange() method in the state SetDefaults of your NinjaScript strategy:
    Code:
    protected override void OnStateChange()
    {
         if (State == State.SetDefaults)
         {
              TraceOrders = true;
         }
    }
    Trace output examples:
    Code:
    Entered internal SubmitOrderManaged() method at 6/2/2015 8:42:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='market order' 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.

    Code:
    Amended open order at 6/2/2015 11:39:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=130.41 StopPrice=0 SignalName='long order to be resubmitted' FromEntrySignal=''
    This trace tells us that a previously submitted order was modified instead of submitting a completely new order.

    Code:
    Ignored SubmitOrderManaged() method at 6/2/2015 12:55:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=129.92 StopPrice=0 SignalName='long order to be resubmitted' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
    This trace provides the reason why our Limit order was ignored.

    Code:
    Cancelled expired order: BarsInProgress=0, orderId='NT-00123-118' account='Sim101' name='long order to be resubmitted' orderState=Working instrument='AAPL' orderAction=Buy orderType='Limit' limitPrice=130.3 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 id=-1 gtd='2099-12-01'
    This trace tells us that our Limit order was cancelled because it had expired.


    A new concept in NinjaTrader 8 is the OnOrderTrace override method.

    This method prevents TraceOrders from printing the traces directly to the output window but instead sends this information to the OnOrderTrace override where you can do logic or format the trace how you would like and then print only what you need to see.

    Code:
    protected override void OnOrderTrace(DateTime timestamp, string message)
    {
         Print(string.Format("{0} {1}", timestamp, message));
    }

    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 8\trace\.

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Johnny, Today, 12:54 PM
    0 responses
    4 views
    0 likes
    Last Post Johnny
    by Johnny
     
    Started by onnb1, Today, 12:45 PM
    0 responses
    2 views
    0 likes
    Last Post onnb1
    by onnb1
     
    Started by pstock805, Today, 08:45 AM
    1 response
    5 views
    0 likes
    Last Post sledge
    by sledge
     
    Started by pstock805, Today, 08:39 AM
    0 responses
    3 views
    0 likes
    Last Post pstock805  
    Started by pstock805, Today, 08:25 AM
    0 responses
    6 views
    0 likes
    Last Post pstock805  
    Working...
    X