Market If Touched / Limit If Touched Orders In Ninja Trader

Posted by TraderWerks | Indicators,Market Analyzer,Site Information,Strategy | Wednesday 27 May 2009 9:35 pm

nudie_juice

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

Narrow Range Market Analyzer Scan

Posted by TraderWerks | Market Analyzer | Saturday 23 August 2008 3:00 am

I was reading Elitetrader ( yes I read it. You probably do to but do not want to admit it. ) A user was looking for a free stock screener to find stocks in a narrow range. I though it was a good idea, and since NinjaTrader is free, and you can get free end of day data, I decided to make a free narrow range screener. So no need to spend $400 bucks. To use, download the NarrowRange Indicator, and set up Market Analyzer below.

Click To Enlarge

 

The formula finds a percentage of the range over a certain period.

               MAX ( High )
Range =  ------------------  - 1
               MAX ( Low )

So we just look at the range over a period, and use that percentage to decide if the range is narrow.

Click To Enlarge

So this is what I can up with. It is an indicator that returns a value if the stock has traded in a narrow range for a certain number of periods. This image is of the Dow 30 stocks , scanned to see if any are in a narrow range for the last 30 days. As of today the only stocks that are trading within a narrow range are WMT, MMM, VZ, IBM, T and JNJ.

The settings are shown in this dialog. The percentage is set as a whole number. So i you were looking for a 10 percent range, you would set this value to 10, as we did here. The indicator returns a value of between 1 and -1. So to hide the display of the non narrow range instruments, I set the reference to zero. The length is 30 and that is how many periods I look back to determine if it is a narrow range or not.

Finally, so you do not have to do this again, we save this analyzer as a template. This save the stocks in the market analyzer and the column settings so you can simply open up the template to see your scan.

Click To Enlarge