Using the Donchian Indicator to enhance your Trading

The Donchian channel is available for purchase here.




Richard Davoud Donchian was an Armenian-American commodities and futures trader, and pioneer in the field of managed futures who came up with a simple intuitive indicator called the Donchian channel. It is basically based on the lowest low value or the highest high value in a given period of time:
USDCAD with Donchian

Calculation


As mentioned, Donchian is based on marking the lowest low line or the highest high line, so visually you see the trend of the product. Whenever the product reached a value which is higher than the last 24 values or lower than the previous ones, a new markup will start until it reverses.
Calculating it with MQL is straightforward, to find out the highest value of the product in a given period, we use the following snippet:
double HighestHigh=iClose(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_CLOSE,TradePeriod,0));

Here, reading from right to left, we first find the shift of the highest value using a call to iHighest, and then, using the return value which is the shift itself, calling iClose to retrieve it. It is possible to run this code with MODE_HIGH, MODE_OPEN etc to get the highest value, but normally I call it with MODE_CLOSE as this is the final value after the price vibrated in that period.
Calculating the lowest low is more or less the same:
double LowestLow=iClose(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_CLOSE,TradePeriod,0));
Here, we just call the iLowest function instead to receive the value.

Now that we have these values, we can mark them on the indicator and paint the chart accordingly. For example, I use the following code to make the painting:
if(i>0)
{
if(CLOSE>HighestHigh && TrendDirection[i+1]!=OP_BUY)
{
TrendDirection[i]=OP_BUY;
SendNotification(StringConcatenate(Symbol()," go long"));
}
else if(CLOSE
{
TrendDirection[i]=OP_SELL;
SendNotification(StringConcatenate(Symbol()," go short"));
}
}
if(TrendDirection[i]==OP_BUY)
ExtMapBuffer1[i]=LowestLow;
else if(TrendDirection[i]==OP_SELL)
ExtMapBuffer2[i]=HighestHigh;


Whenever the trend changed direction, I get notified over Metatrader, but it is possible also to get an E-mail or any other means of communication. This way, whenever new highs or lows are achieved, I am notified immediately and can make trading decisions on how to proceed with my positions.

Usage


I mostly run this indicator on the hourly chart of the products I trade. It is not too short time frame for randomness and noise to kick in, and not too long that the trend might be discovered towards the end. On my mobile, the notifications will look like:
EURGBP go long 10:30
EURGBP go short 12:45
...

As it is just one of the indicators I use, I don't rush and open a position, rather check the current market conditions and news to see what the overall sentiment for this product.
For example, I was long EURGBP the last month, strongly believing the Brexit does good to the EUR, the upcoming elections and many supporting ideas for me to follow. But actually, after looking at the Donchian around the time I opened the order, I noticed it is a free fall, which only recently is coming towards an end:
EURGBP Donchian
Looking at the indicator behavior around the 8th September, shows a clear sign of an upcoming bearish trend of EURGBP, with a short reversal and then down again. So, going long was not the right choice at the time and closing the positions was the right choice.

Normally, as I am a volatility trader, I don't look for trend and trade both directions of the market to capture profit. But still, as I like simplicity, the Donchian give me that trending piece of information I need to make a decision whether it is a ranging market which is my favorite or a trending market and then my decisions on taking a side are critical.

Turtle Trading


Interesting point was that during the 80's, there was the famous experiment to prove that anyone can be a trader, so called the turtle traders. And as mentioned in the original rules which can be found here - http://bigpicture.typepad.com/comments/files/turtlerules.pdf. The trading entry system was based on breakouts, where breakout was defined as the price exceeding the high or low of a particular number of days. Thus a 20-day breakout would be defined as exceeding the high or low of the preceding 20 days.
In my trading, I use it more as a flag signaling me whether I should go into a trade or not, but only after I have several positions and I want to hedge them, plus, I am using the hourly chart as mentioned above.

Code


The full code is here and in the downloads page for you to use it, feel free to contact me for any questions:
//+------------------------------------------------------------------+
//| Donchian |
//| Copyright 2017, IlanTree |
//| http://www.ilantree.com |
//+------------------------------------------------------------------+
#property copyright "Roy Meshulam"
#property version "1.00"
#property description "As a user of this trading system, you acknowledge and agree to accept complete responsibility for ANY and ALL results in your trading account. You acknowledge and agree that you are fully aware of the high risk associated with trading. You acknowledge and agree that leveraged currency trading can cause losses greater than your beginning balance. You acknowledge and agree that Roy Meshulam has made NO promises or guarantees suggesting that this trading system will result in a profit or loss."
#property link "http://www.ilantree.com"
#property strict

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_width1 3
#property indicator_width2 3

input int TradePeriod=24;// Donchian channel period

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double TrendDirection[];

static datetime TimeStamp;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);

SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
IndicatorDigits((int)MarketInfo(Symbol(),MODE_DIGITS));

IndicatorShortName("Donchian Channels ("+IntegerToString(TradePeriod)+")");
SetIndexLabel(0,"Lower channel");
SetIndexLabel(1,"Upper channel");

SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,TrendDirection);

return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1); int limit=Bars-1-counted_bars; if(counted_bars==0) limit-=1+1; for(int i=limit; i>=0; i--)
{
TrendDirection[i]=TrendDirection[i+1];

ExtMapBuffer1[i]=ExtMapBuffer2[i]=EMPTY_VALUE;

double HighestHigh=iClose(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_CLOSE,TradePeriod,i+1));
double LowestLow=iClose(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_CLOSE,TradePeriod,i+1));

double CLOSE=iClose(Symbol(),0,i);

if(i>0)
{
if(CLOSE>HighestHigh && TrendDirection[i+1]!=OP_BUY)
{
TrendDirection[i]=OP_BUY;
SendNotification(StringConcatenate(Symbol()," go long"));
}
else if(CLOSE {
TrendDirection[i]=OP_SELL;
SendNotification(StringConcatenate(Symbol()," go short"));
}
}

if(TrendDirection[i]==OP_BUY)
ExtMapBuffer1[i]=LowestLow;
else if(TrendDirection[i]==OP_SELL)
ExtMapBuffer2[i]=HighestHigh;
}

return(0);
}
//+------------------------------------------------------------------+

Comments