A practical question about coding the Donchian Trend system

Discussions about the testing and simulation of mechanical trading systems using historical data and other methods. Trading Blox Customers should post Trading Blox specific questions in the Customer Support forum.
Post Reply
fc
Full Member
Full Member
Posts: 13
Joined: Mon Dec 12, 2011 8:49 am

A practical question about coding the Donchian Trend system

Post by fc » Thu Mar 01, 2012 1:32 pm

The Donchian Trend system, as shown in Way of the Turtle, uses a 20-day breakout for entry, 10-day breakout for exit, and a 2ATR stop-loss. There is also a moving average filter: You can only take longs if the 25-day MA is above the 350-day MA, and vice versa for shorts.

But how should one code this? It seems absolutely impossible to code this in "real time", i.e. such that I enter and exit trades as soon as events occur, because for a given day, I don't know which happened sooner: the high or the low.

For this reason, isn't it the case that I have to look at the market after the market closes on each day, and then place my trade according to the next day's opening price? If this is the case, how do you actually implement the Donchian Trend system in code?

Here is one idea that I have:
  1. The market has closed on a particular day. I look at the high/low for the day. I calculate the moving averages based on the closing prices for this and past days. If we have the highest high/lowest low for the past 20-days (and assuming I currently don't have any trade on and that the moving average filter is satisfied), I enter a new trade by buying/selling on the next day's opening price. I continue to repeat this process for all days going forward.
  2. I deal with the 10-day exit breakout in a similar way.
  3. However, I can deal with the 2-ATR stop loss in "real time", i.e. as soon as it occurs because I'm entering trades on market open, and I can see on a given day using the high and low prices whether the stop was hit.
Is this the correct way to do it?

sluggo
Roundtable Knight
Roundtable Knight
Posts: 2986
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo » Thu Mar 01, 2012 2:53 pm

Since the Donchian system is one of the presupplied trading systems that comes for free when you buy Trading Blox software, it is discussed in the Trading Blox User's Guide (section 11.10). You could download the TBUG from the Trading Blox sales website and have a look.

You may also want to research a trading order type which you can give to your broker: the "Stop Order". This is another way to trade, beside the more familiar "Market Order" and the less familiar "Limit Order".

These links may get you started: (one) , (two) , (three) , (four) . A great way to learn more is to phone your broker and have a discussion.

fc
Full Member
Full Member
Posts: 13
Joined: Mon Dec 12, 2011 8:49 am

Post by fc » Thu Mar 01, 2012 5:18 pm

I looked through the docs just now. Is there any way I could get the Trading Blox code for the Donchian Trend system? It's not there in the guide. I think that would be very useful to me to help me understand it in the best way.

Toosday
Roundtable Fellow
Roundtable Fellow
Posts: 70
Joined: Fri Jun 03, 2011 11:21 am
Location: Austin, TX

Post by Toosday » Sat Mar 03, 2012 10:44 am

As a suggestion, I do not believe having someone giving you the code is the best way to understand the Donchian system. Going through iterations of decision trees helped me understand the systems and their execution the best. There is no correct time or way to send orders as long as you test the way you trade. You have the basics so spend some time on the details which happen to be very important.

For some, having automated stop, OSO or OCO orders always open creates trade anxiety if you do not monitor the markets constantly. For others, they like a hands off approach. I have adjusted the way I place orders to my personality and suggest you look at this as well.

stopsareforwimps
Roundtable Knight
Roundtable Knight
Posts: 199
Joined: Sun Oct 10, 2010 1:47 am
Location: Melbourne Australia

Re: A practical question about coding the Donchian Trend sys

Post by stopsareforwimps » Sun Mar 04, 2012 2:20 am

fc wrote:The Donchian Trend system... But how should one code this?
You could try coding up this exercise, and working on it until you get it right to the cent. At that point you will probably understand it.

http://www.seykota.com/tribe/TSP/SR/index.htm

Post Reply