Market If Touched / Limit If Touched Orders In Ninja Trader
MIT/LIT ORDERS MIA IN NINJATRADER
With any trading platform, there will always be ONE feature that you need that is not implemented. For me that is Limit If Touched orders with a negative offset in NinjaTrader. I was on a long trip recently and I finally had time to implement MIT/LIT for a strategy I was writing.
Long flights are great for getting work done. I will dread the day they allow cell phones in all planes.
On, on to the orders. Market if touched are a very similar to stop limit orders. They are both types of orders that occur only if the price reaches a certain level. With a Market If Touched order, once a price reaches a certain level, a market order is executed.
In Ninjatrader, there are some limitations to stop limit orders in strategies which are annoying, such as setting a negative stop price. I guess there is some reason for that, but it is beyond me. Maybe in NinjaTrader 7 they will have it for strategies.
If you have used StopLimit orders before and have seen an error about an improperly placed  order, then you know that I am talking about.
For these situations, we can use a Market If Touched or Limit If Touched order to accomplish the same thing , without the annoying errors and stopping of your strategy.
MIT / MARKET IF TOUCHED
A buy market-if-touched order is an order to buy at the best available price, if the market price goes down to the “if touched” level. As soon as this trigger price is touched the order becomes a market buy order.
A sell market-if-touched order is an order to sell at the best available price, if the market price goes up to the “if touched” level. As soon as this trigger price is touched the order becomes a market sell order.
LIT / LIMIT IF TOUCHED
Just like MIT order except that a limit order instead of a market order. This is the closest one to a stop limit order.
IMPLEMENTING IN CODE
You can only do this if you are writing code, I do not believe the strategy wizard can do this. I am not sure, I rarely use strategy wizard for anything.
This may be considered advanced programming, but it is not that hard. It just looks harder than it is. It is considered ‘advanced’ programming by the people on the Ninja Trader support forum, so they will not be that helpful.
Now for either of these orders , you have to monitor the prices, in-between bar updates. For that, we use OnMarketData. This recieves the price every time the price changes. This also increases the work your computer has to do , so be careful.
protected override void OnMarketData(MarketDataEventArgs e)
The variable e has a MarketDataType attached, and this is what you want to trigger you trade from. There are different things you can trigger from.
- MarketDataType.Ask
- MarketDataType.Bid
- MarketDataType.DailyHigh
- MarketDataType.DailyLow
- MarketDataType.DailyVolume
- MarketDataType.Last
- MarketDataType.LastClose
Mind you, not every data provider furnishes those. So when we see the price we want e.Price , if it is above our buy stop, we can then enter an order.
if (e.MarketDataType == MarketDataType.Ask)
{
if ( e.Price >= touch_price )
{
EnterLimit ( ) ;
}
}
Â
Now, this is just a start, and there are a lot of things you can do with this. Such as shorting when the bid reaches a certain price and so on.
MIT definition from Wikipedia








