Unmanaged Approach
<< Click to Display Table of Contents >> 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.
Getting started 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 OnStateChange() method designating the IsUnmanaged 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.
Please note that you will not be able to mix order methods from the two approaches. When setting IsUnmanaged to true, you can only use Unmanaged order methods in the strategy. |
Working with Unmanaged order methods
Order SubmissionOrder submission with the Unmanaged approach is done solely from a single order method. Parameterizing the SubmitOrderUnmanaged() 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.
It is critical to assign an Order 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 Order objects:
•An Order object returned from calling an order method is dynamic in that its properties will always reflect the current state of an order •The property <Order>.OrderId is NOT a unique value since it can change throughout an order's lifetime •To check for equality you can compare Order objects directly
Order ModificationUnlike 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 Order object you wish to modify so it is important to hold onto those for any active order you have in your strategy.
Order CancellationSimilar to the live until canceled technique from the Managed approach, canceling orders can be done through the CancelOrder() method.
Signal TrackingSince 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:
Methods utilizing signal names like BarsSinceEntryExecution() and BarsSinceExitExecution() can still be used though. |
Critical considerations when using Unmanaged order methods
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.
OverfillsOverfills 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 canceled. Overfills 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 overfill can occur is highly dependent on the specific strategy programming. By default, NinjaTrader will protect against overfills even though you are using the Unmanaged approach by halting the strategy, but should you decide to custom program your own overfill handling it is up to you to either prevent overfills from being a possibility in your code or by introducing logic to address overfills should one occur.
Order rejectionsOrder 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 LossEven 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 OnConnectionStatusUpdate() to properly recover all aspects of your strategy in the manner you desired. |
Cancels a specified order. |
|
Amends a specified Order. |
|
An unmanaged order property which defines the behavior of a strategy when an overfill is detected. |
|
Determines if the strategy will be using Unmanaged order methods. |
|
Generates an Unmanaged order. |