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

Book Review : Mean Markets And Lizard Brains

Posted by TraderWerks | Indicators | Tuesday 12 May 2009 7:18 am

mean_market_lizard_brain
I usually read books to help me find trading and indicator ideas. This book doesn’t really address either of those points. This is more about the psychology of trading and ‘beahvorial finance’.  It is more of a ‘Intro To Behavioral Finance” you might say.

 I have talked about behavioral finance before here .

This book caught my eye because [1] It had a picture of a lizard on it , and [2] Taleb recommended it, and I am a big fan of his even if I think he is a bit too pompous on TV.

SHORT REVIEW

Good book if you liked Taleb’s Black Swan book. It is an easy read and makes you think about how our ‘Lizard Brain’ causes us to make crappy trading decisions.  Recommended.

Keep reading for the full review.

INTRO BEHAVIORAL FINANCE

The author , Terry Burnham, worked on behavioral finance for 10 years at Harvard including teaching, which puts him in the egg head category.

The book is divided into four sections. The first part , The New Science of Irrationality, and the last part, Profiting from the New Science of Irrationality are the most interesting to me.

EDUTAINMENT

The book tries to Edutainment ( hat tip to Boogie Down Productions) , which is entertaining and educational. It does not excel at either , but also does not fail.

Edutainment (also educational entertainment or entertainment-education) is a form of entertainment designed to educate as well as to amuse.

There are a lot of stories in the book, and I think this guy would have been a pretty fun professor in class. 

 If you have been around for a while, you probably have heard a lot of these stories, but he does put them into context.  Things like German Hyperinflation, the chances of making it to the NBA and ‘This is Spinal Tap’ quotes.

LIZARD BRAIN

The book centers around our ‘lizard’ brains. Which is non ‘pre frontal cortex part of our brain. The ‘pre-fontal cortex is what we use for rational thought, trading decisions, etc.

The rest of our brain, the lizard part , is responsible for everything else. Fight or flight, loss aversion, fear of being eaten and things like that are all handled by our lizard brains.

The final part of the book gives rules on how we can invest without out using our lizard brains.

GOOD PARTS

  1. Excellent intro to behavioral finance
  2. Good attempt at making a subject more relatable
  3. The author was bearish on the market in 2005

NOT SO GOOD PARTS

  1. The book is dated. Has a lot of references to the housing crisis.
  2. Tries to be ‘edutainment’, does neither well
  3. The author was bearish on the market in the book

It is surprising hard to write a post about this book without overusing the term Lizard brain. My apologies.

Turtle Trading Strategy With Source

Posted by TraderWerks | Strategy | Monday 4 May 2009 12:20 pm

sea_turtle
THE TURTLES

In 1983 & 1984 Richard Dennis recruited 21 men and 2 women who both became known as the “turtles.” The program with the turtles ended in 1988, with many of the ‘turtles’ have going on to successful careers as commodity trading advisors.

If you have not hard about the Turtles there is a good book about the legendary ‘Turtles’, named “Way Of The Turtle“.

I was reading Curtis Faith’s book “Way Of The Turtle” over the weekend.  I think it is the best book on the Turtles on the market today. There may be other books that are better written or edited than this one, but I consider this one the best, as it was written by one of the original turtles.

Now with thatout of the way, onto one of the systems they used.

DONCHIAN CHANNEL

The donchian channel is a volatility based indicator. Like other volatility indicators, and especially channel indicators, the donchian channel is usually used to identify a break out of a price range.

The donchian channel is displayed as high and low bands , and therefore it looks similar to other volatility indicators such as Bollinger Bands.

DONCHIAN CHANNEL TURTLE SYSTEM

This system is the channel breakout system from the book. It consists of two parts. A n-period channel breakout, and a trend filter to only trade breakouts with the trend.

The Donchian channel is a 20 period breakout, so that you enter a position if the high or low passes the 20 period high or low.

The trend filter is a 50/300 period moving average crossover. If the 30 period moving average is higher than the 300 period moving average then only take long trades.

So this system uses this breakout to initiate trades, while still being a trend following system via the the trend filter to only initiate trades ‘with the trend’.

MY VERSION

Lately there have been a lot of trading days, so think a trend following system would have performed very well in the last few weeks ( during this bull run ). I coded this for Ninja Trader 6.5 and the source is a zip file below. Just import the zip file from the NinjaTrader utility menu, selecting ‘Import Ninjascript” and selecting the zip file.

I did not make many changes to the system for this version yet. Later I will post a more modified version of the system.

DOWNLOAD DONCHIAN SOURCE FOR NINJA TRADER 

The difference for this system is that the system works as a day trading system. The original system was based on daily prices, this one is based on 5 minute bars, although you can run it on any time frame.

I used a 2 * ATR trailing stop. The systems also exits all trades at the end of the day.

dchannel_results
RESULTS

Well, as you would expect, it performed as most trend following systems do. Trend following systems tend to have a lot of small losses and fewer, but larger wins to make up for it.

I back tested the system on the March ES contract from 12/21/2008 to 3/21/2009. It did not fare well, losing $4475 before comms. But let’s look past that at how well it did as a trend following system.

Trend following systems are profitable less than 50% of the trades.The Donchian channel In this case, it was profitable 31% of the time.

The largest win was about 2.5 times the largest loss. The average win was almost 50% larger than the average loss. Also in line with trend following systems.

NEXT UP : MODIFICATIONS

Now that I have the base line using bog standard settings for the Donchian channel system. I want to make some modifications and post them along with modified source.

If you have any ideas you would like to see, write me at blog @ traderwerks.com