Top Menu

NinjaTrader 7 Strategy Development Unmanaged Approach

The Unmanaged approach is reserved for VERY EXPERIENCED programmers. In place of the convenience layer that the Managed approach offered, the Unmanaged approach instead offers ultimate flexibility in terms of order submission and management. This section will discuss some of the basics of working with Unmanaged order methods.

 

To be able to offer you the flexibility required to achieve more complex order submission techniques, NinjaTrader needs to be able to know if you are going to be using the Unmanaged approach beforehand.

 

In the Initialize() method designating the Unmanaged property as true signifies to NinjaTrader that you will be using the Unmanaged approach. Setting this will effectively prevent any of the signal tracking and internal order handling rules that were present in the Managed approach.

 

protected override void Initialize()
{
    Unmanaged = true;
}

 

Please note that you will not be able to mix order methods from the two approaches. When setting Unmanaged to true, you can only use Unmanaged order methods in the strategy.

Order Submission

Order submission with the Unmanaged approach is done solely from a single order method. Parameterizing the SubmitOrder() method differently will determine what kind of order you will be submitting. Please note that these orders are live until cancelled. Should you want to cancel these orders you will need to use the CancelOrder() method or wait till the orders expire due to the strategy’s time in force setting.

 

In the example below, a buy limit order to enter a long position is working at the bid price provided that the close price of the current bar is greater than the current value of the 20 period simple moving average.

 

protected override void OnBarUpdate()
{
    // Entry condition
    if (Close[0] > SMA(20)[0] && entryOrder == null)
         entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, GetCurrentBid(), 0, “”, “Long Limit”);
}

 

It is critical to assign an IOrder object to keep track of your order or else you will not be able to identify it in your code later since there is no signal tracking when using Unmanaged order methods. Please be aware of the following information about IOrder objects:

 

An IOrder object returned from calling an order method is dynamic in that its properties will always reflect the current state of an order
The property <IOrder>.OrderId is NOT a unique value since it can change throughout an order’s lifetime
The property <IOrder>.Token is NOT a unique value since it will change as the strategy transitions from historical to real-time
To check for equality you can compare IOrder objects directly

 

 

Order Modification

Unlike the Managed approach where you could modify a working order by calling the entry order method again with your new parameters, the Unmanaged approach requires the utilization of the ChangeOrder() method. The ChangeOrder() method requires you to have access to the IOrder object you wish to modify so it is important to hold onto those for any active order you have in your strategy.

 

protected override void OnBarUpdate()
{
    // Raise stop loss to breakeven when you are at least 4 ticks in profit
    if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice && Close[0] >= Position.AvgPrice + 4 * TickSize)
         ChangeOrder(stopOrder, stopOrder.Quantity, stopOrder.LimitPrice, Position.AvgPrice);
}

 

 

Order Cancellation

Similar to the live until cancelled technique from the Managed approach, cancelling orders can be done through the CancelOrder() method.

 

protected override void OnBarUpdate()
{
    // Cancel entry order if price is moving away from our limit price

    if (entryOrder != null && Close[0] < entryOrder.LimitPrice – 4 * TickSize)

    {

         CancelOrder(entryOrder);

 

        // If the entryOrder IOrder object is no longer needed I should reset it to null in the OnOrderUpdate() method

    }
}

 

 

Signal Tracking

Since the Unmanaged approach does not utilize NinjaScript’s signal tracking the features associated with it will no longer be relevant. The following properties and their associated concept cannot be used with Unmanaged order methods:

 

EntriesPerDirection

EntryHandling

 

Methods utilizing signal names like BarsSinceEntry() and BarsSinceExit() can still be used though.

When using the Unmanaged approach it is imperative to understand that NinjaTrader has many safety mechanisms that were present in the Managed approach turned off. There are critical issues that must be considered and your strategy must be programmed in a manner that addresses these concerns. Failure to do so may result in a serious adverse affect on your trading account.

 

Over-Fills

Over-Fills is a serious issue that can occur when using complex entry conditions that bracket the market in both directions end up with both entries being filled instead of one being cancelled. Over-Fills can also occur when you place a trade quickly hoping to close a position while a prior order to close the same position already had an in-flight execution. The exact scenarios in which an over-fill can occur is highly dependent on the specific strategy programming. By default, NinjaTrader will protect against over-fills even though you are using the Unmanaged approach by halting the strategy, but should you decide to custom program your own over-fill handling it is up to you to either prevent over-fills from being a possibility in your code or by introducing logic to address over-fills should one occur.

 

Order rejections

Order rejections are not local to using Unmanaged order methods, but the impact of improper rejection management is just as detrimental. Please be sure the strategy has significant contingency programming to handle order rejections so as to prevent your strategy from being left in some sort of limbo state. This is especially important if you decide to turn off RealtimeErrorHandling protection.

 

Connection Loss

Even though NinjaTrader provides connection loss handling features it is still important to ensure your recovered strategy’s internal state is not in limbo. Should you have internal variables tracking various information it may be necessary for you to program your own additional connection loss handling into OnConnectionStatus() to properly recover all aspects of your strategy in the manner you desired.

Disclaimer Trading & investment carry a high level of risk & MicroTrends® does not make any recommendations for buying or selling any financial instruments. We do not offer trading or investment advice. We are a software company & we only offer educational information on ways to use our sophisticated MicroTrends trading tools. It is up to our customers & other readers to make their own trading & investment decisions or to consult with a registered investment advisor.

Risk Disclosure Futures, CFDs & forex trading contains substantial risk & 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 life style. Only risk capital should be used for trading & only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. Please read the full risk disclosure here.

Hypothetical performance results have many inherent limitations, some of which are described below. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown; in fact, there are frequently sharp differences between hypothetical performance results & the actual results subsequently achieved by any particular trading program. One of the limitations of hypothetical performance results is that they are generally prepared with the benefit of hindsight. In addition, hypothetical trading does not involve financial risk, & no hypothetical trading record can completely account for the impact of financial risk of actual trading. for example, the ability to withstand losses or to adhere to a particular trading program in spite of trading losses are material points which can also adversely affect actual trading results. There are numerous other factors related to the markets in general or to the implementation of any specific trading program which cannot be fully accounted for in the preparation of hypothetical performance results & all which can adversely affect trading results.

Testimonials appearing on this website may not be representative of other clients or customers & is not a guarantee of future performance or success.

NinjaTrader® is a registered trademark of NinjaTrader Group,LLC. No NinjaTrader company has any affiliation with the owner, developer, or provider of the products or services described herein, or any interest, ownership or otherwise, in any such product or service, or endorses, recommends or approves any such product or service.

MicroTrends® is a registered trademark of MicroTrends Ltd.
MICROTRENDS LIMITED is a company registered in England & Wales. Registered number: 5704475.
Registered office: 30-34 NORTH STREET, HAILSHAM, EAST SUSSEX, BN27 1DW. UK.
VAT Registration No: 879467255