Go Back   NinjaTrader Support Forum > NinjaScript Educational Resources > Tips

Tips Official NinjaScript tips and tricks

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 10-14-2007, 12:06 PM   #1
NinjaTrader_JoshP
NinjaTrader Product Manager
 
NinjaTrader_JoshP's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,459
Thanks: 1
Thanked 379 times in 106 posts
Default 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 at 12:17 PM.
NinjaTrader_JoshP is offline  
Reply With Quote
Old 06-03-2015, 12:39 PM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,705
Thanks: 29
Thanked 1,199 times in 1,120 posts
Default

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.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Explain TraceOrders "Ignored" & Replay Speed Impact on Fills OnePutt Platform Technical Support 1 09-08-2007 02:16 PM
TraceOrders MrBaffalo General Development 2 07-11-2007 09:58 AM
TraceOrders Display Format KBJ Strategy Development 1 05-01-2007 05:13 PM


All times are GMT -6. The time now is 03:09 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.