Main Concepts to Consider when working with the unmanaged order handling in NinjaTrader

NinjaTrader uses the managed order handling mode by default and you can run into a few scenarios when you wrote all of your code and suddenly your orders start getting ignored although it seems that everything you wrote is very logical.


There are quite a few examples but in this article, we will talk only about one of the most common ones which is when you place two stop orders to enter the market with one above the market for long and one below the market to short the market.



NinjaTrader default managed mode is not going to allow you to do this and will ignore one or maybe even both of your orders. The solution is to set NinjaTrader to the unmanaged mode in the OnStateChange() State == State.Default by including IsUnmanaged = true part.


Once that is done your order signature will also have to change slightly. 


Order entryMarketOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, PositionSize, LimitPrice, StopPrice, "", EnterLongName);


The first parameter is used to specify bars in progress which means you need to mention which data series you wish the order to execute on. Put 0 if is the initial one. OrderAction and OrderType are quite standard functions but the next two parameters can be a little bit confusing and can lead to a lot of time spent realizing whats wrong.


If you are entering using a market order set LimitPrice and StopPrice to zero. If you are using limit orders only set the value for the limit price parameter and put 0 for the stop price and vice versa for the stop.


Order entryStopOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Stop, PositionSize, 0, StopPrice, "", EnterLongName);


Order entryLimitOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, PositionSize, LimitPrice, 0, "", EnterLongName);


Another challenge that you will face when using NinjaTrader UnManaged approach is the fact that you will have to handle absolutely all order questions manually. This can lead to quite a few bugs and hours of trying to understand what’s going on!!!


Let’s imagine you enter 3 lots long. Your subsequent logic implies that when you hit your first profit target you close only 1 lot and you need to put your initial stop to break even and when you hit your next profit target you close another lot to be left with 1 last lot that you wish to trail.



In the unmanaged approach, you need to handle everything. For example, if you never hit profit target 2 and quit position using breakeven you need to cancel the remaining orders, you need to adjust position sizes after scale outs, you need to do all the work that is done automatically in the managed approach where if you hit a profit target and your full position is closed the rest of the orders that were related will be automatically handled and canceled for you by the managed approach.


Overall, you need to have a very good reason to use the unmanaged approach because although it does give you full control it is way more time consuming to code and test.


Hope you find the article helpful Please subscribe to stay updated!