Page 1 of 1

A practical question about coding the Donchian Trend system

Posted: Thu Mar 01, 2012 1:32 pm
by fc
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?

Posted: Thu Mar 01, 2012 2:53 pm
by sluggo
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.

Posted: Thu Mar 01, 2012 5:18 pm
by fc
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.

Posted: Sat Mar 03, 2012 10:44 am
by Toosday
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.

Re: A practical question about coding the Donchian Trend sys

Posted: Sun Mar 04, 2012 2:20 am
by stopsareforwimps
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.