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

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

Why TraderWerks ?

Posted by TraderWerks | Strategy | Monday 27 April 2009 6:52 pm

risk_factory_mediumTraderWerks. The first part, trader, we can all relate to. The second word , Werks is a German word that means factory.Stupid name at first, but when you think about it, it makes sense.

So now you have a clue to why I named this site TraderWerks. This post has been a long time in the making. Mainly because it is not just an answer for the curious, but an insight into the way I look at trading. I am by no means the worlds greatest trader, I just want to share my thoughts.

TRADING IS BORING

Trading is a lot more like working in a factory than you might think.

I focus on short term auto mated trading. Day trading you might say with a computer. When you are running systems it can be very, very boring. Really it is, since your systems make all the decisions, you are just along for the ride. Factory work is boring because it is factory work, trading is boring because it like like factory work with a better view.

On the setups I use most often, I have programmed an alarm sound when it comes time to place a order and open/close a position. Maybe 10 alerts over 6 and a half hours ( my current system anyway ). Of those ten alerts, maybe five trades will actually be signaled. I have semi automated my system, and I will fully automate one day, but for now, I am the human that makes sure a false signal is not generated by a Federal reserve speech or just a not a head fake from the ES. Most of the time, I just let the system do what it is programmed to do.

So here I am , pressing a button like a trained monkey every half an hour to an hour or every couple of hours. It doesn’t hurt my feelings to be called a trained monkey, since I am the who built the button I am pushing. But the time in between waiting for the the setup to occur is ‘downtime’. I can read email and such, but I still want to stay close to the system during trading hours.

LIKE A FACTORY

Day trading for me is not  the helter skelter of ‘Trading Places‘ ( One of my favorite Eddie Murphy movies ).

You go to the factory, do the best you can making widgets and go home and have a beer. No theatrics.

For me, my trading day is pretty much the same. I make sure my computers are running, checking out the systems, checking the previous day’s trade, updating my trading journal. Even though I auto trade, I still keep a trading journal which gives me  ideas on how to improve my systems. My trading consists of following my trading plan and following my system.

SO WHAT DOES TRADING BETTER HAVE TO DO WITH A FACTORY?

Both trading and working in factory have to do with following a plan. In trading, we have our trading plan, in a factory we have a work schedule. In a factory,  follow the work schedule and worry about your execution. In trading you follow your trading plan, and you worry about following that plan. I am sure you already have a trading plan, but in case have not written it down yet…….

A trading plan is a personal thing, so everyone’s trading plan will look different. IMHO, it should have at least three parts.

  1. Entries – Your setups
  2. Exits – Profit targets, Stop Losses
  3. Money Management – Risk management

The first step to following a trading plan is writing out your trading plan. The key is writing it out. A trading plan is something you could actually explain to another person. The process of writing it out helps clarify our trading plan. A lot of us have vague trading plans in ‘our head’, but that is not a trading plan, that is one step from random trading. So, put together your trading plan, trade it like you are working in a factory, and you trade better.

SO REALLY, WHY TRADERWORKS.COM?

Because TraderWorks.com and TraderFactory.com  were already taken.

“Think Like A Trader”

Posted by TraderWerks | Strategy | Monday 13 April 2009 7:50 pm

clamwin_logo

THINK LIKE A TRADER

Some scientists decided to do a study on how do people trade ‘like a trader’, and do they perform better when  people trade better when they ‘Think Like A Trader”.

This paper specifically takes a look at traders and loss aversion. If one ‘Thinks Like A Trader” will they be less risk averse and trade better. The answer is yes. I posted a link to the paper below.

For simplicity sake, I will define loss aversion as:

losses hurt more than gains feel good

That is taht people feel a lot more pain from losing $100 than from making $100. Thus, we make based decisions based on not making loses.

What the study did was ask the guinea pigs subjects to “Think Like A Trader” and not to worry about the losses. It seems to have worked. They have a lot of graphs and charts in the paper that you can check out in your free time.

SIM TRADING

A lot of people can sim trade better than they can trade actual money. I could have titled this post “Why I Am Great In Simulation Trading And Suck In Real Life” but that would have been just too long.

For most people, when we sim ( trading in simulation mode without money on the line ) we take more risks and tend to do better. When it comes to actually trading, we tend to suck. Time seems to slow down while we are watching every tick.

The reason some of us ( most of us ) , sim trade better than than real life trade is that were are in a better state emotionally to trade our systens and not second guess ourselves. We are thinking like a trader because we do not fear the losses.

AUTOMATED STRATEGIES ALWAYS THINK LIKE A TRADER

That is the beauty of an automated system. It is mechanical and it does think like a trader.

You should see my face when I watch the strategy trade. My strategy will make a trade and I will watch it and just want to close out the trade before I lose too much or lock in a profit. Most of the time, my strategy proves me wrong and stays in the trade. My strategy trades like a machine because it is a machine.

CONCLUSION

When I read an academic paper, I usually read the conclusion first and work my way back from there. I also read the ends of novels first, but considering how many novels I read now ( pick a number between nil and zero ) , it does not matter.

In real life, you need to fear and respect losses but not let them overwhelm your trading. Try to ‘Think Like A Trader” and don’t let the losses affect your trading or your system.

So when you can trade on a sim, and you move to trading a live account, remember to try to keep the same detachment you had when you were trading on a sim.

NOTES

The image is by Sakurako Kitsa, is a Bento box in the shape of a Starbuck’s Green Tea Frappuccino .

You can read the whole paper herepnas-2009-sokol-hessner-0806761106

Gap Fade Ninjascript Strategy : Five Profitable RIMM Trades In A Row in 10 Days

Posted by TraderWerks | Strategy | Tuesday 28 October 2008 4:24 am

Looking at this wild week in the market I decided to look at the old gap trade. The gap trade is fading a gap open, and used to be a staple trade, but in the last few years it has not worked as well.. For example , if a stock opens up 2%, you sell it and hope for the gap to close.

So I coded up a NinjaScript strategy to trade the gap trade and took a look at RIMM. No real reason I picked RIMM, it is just one of those volatile internet type stocks. I have not tested the strategy on other stocks, but feel free to test it out.

Nine trades , all profitable, for a cumulative profit of 21% over the last couple of weeks. I have not done testing on other stocks, but it seems like the gap trade is working now.

Take a look at the image on my right. You can click on it to get a full size image. This is an image of the strategy analyzer, which is backtesting. The total net profit was $9.53 over two weeks which is not bad for a $44 stock. If you will notice that there were five trades, with four long trades in this market. The market has been wild so this strategy has been making long trades after some of these selloffs.

You can download the Gap Trade Strategy here. You need to run NinjaTrader 6.5 which pretty much everyone runs. You do have to register it, but it is mainly so you can read the legal mumbo jumbo that my legal guy wants. You just have to read the license and click ok.

DOWNLOAD Gap Trade Strategy

HOW TO USE THE STRATEGY
[1] The strategy only works on intraday data, not daily data.
[2] There is also only one parameter and that is the percentage of the gap for the trade to occur. So a setting of 2 would be a 2% gap.
[3] The strategy closes all trades at the end of the day.