Trading with Donchian Channels

Alexander Fedosov | 2 June, 2017

Contents

Introduction

The Donchian Channel is a technical indicator developed in early 1970s. First it was called a Moving Channel, and later was renamed after its creator Richard Donchian. This indicator measures the degree of market volatility based on a given price range using recent lows and highs. The Donchian channel is drawn as two lines, between which the price fluctuates. Sell or buy signals are formed when the price breaks the lower or upper channel border respectively. The author recommended to draw the channel using the price range equal to 20 (an average number of business days in a month) and the D1 timeframe.


Operation Principle and Application of the Donchian Channel

I will not reinvent the wheel and will not create another program implementation of this indicator. I decided to use its Donchian Channels System modification, which perfectly characterizes the trading style based on this system. In Fig.1 pink and blue candlesticks show the areas where the channel borders are broken, market entry is supposed in this places.


Fig1. Operating principles and entry points based on the Donchian Channel.

Pay attention to red areas marked on the chart. They indicate the main disadvantage of the Donchian channel — the so-called false breakouts, after which the price rolls back into its range. Therefore, entering the market by only using the Donchian Channel without additional confirmation would be reckless. In order to have a clearer understanding of the indicator idea, let us analyze the parameters and implementation of this modification:

//+----------------------------------------------+
//|  Indicator input parameters                  |
//+----------------------------------------------+
input uint           DonchianPeriod=20;            // Averaging period
input Applied_Extrem Extremes=HIGH_LOW;            // Type of extrema
input uint           Shift=2;                      // Horizontal shift in bars
//+----------------------------------------------+

  • Averaging period is the used price range.
  • Type of extrema means the type of price values used in calculations. A classical setup is used by default, which means using candlestick high and low values.
  • Horizontal shift in bar means shifting the channel.

Let us dwell on extrema types, because in this modification not only High and Low can be used. Below are possible options and software implementation:

//+----------------------------------------------+
//|  Declaration of enumeration                  |
//+----------------------------------------------+
enum Applied_Extrem //Type of extrema
  {
   HIGH_LOW,
   HIGH_LOW_OPEN,
   HIGH_LOW_CLOSE,
   OPEN_HIGH_LOW,
   CLOSE_HIGH_LOW
  };

  • HIGH_LOW is the classical application of candlestick Highs and Lows.
  • HIGH_LOW_OPEN — in this interpretation, the upper channel border is drawn based on the average value between the open price and the candlestick highs in the selected price range. Candlestick lows are used for the lower border.
  • HIGH_LOW_CLOSE — the upper channel border is drawn based on the average value between the close price and the candlestick highs in the selected price range. Candlestick lows are used for the lower border.
  • OPEN_HIGH_LOW — the upper border is drawn based on the highest open prices over the selected price range, and lowest ones are used for the lower border.
  • CLOSE_HIGH_LOW — the upper border is drawn based on the highest close prices over the selected price range, and lowest ones are used for the lower border.

The listing of implementations of different type of extreme values is available below:

for(bar=first; bar<rates_total && !IsStopped(); bar++)
     {
      switch(Extremes)
        {
         case HIGH_LOW:
            SsMax=high[ArrayMaximum(high,bar,DonchianPeriod)];
            SsMin=low[ArrayMinimum(low,bar,DonchianPeriod)];
            break;

         case HIGH_LOW_OPEN:
            SsMax=(open[ArrayMaximum(open,bar,DonchianPeriod)]+high[ArrayMaximum(high,bar,DonchianPeriod)])/2;
            SsMin=(open[ArrayMinimum(open,bar,DonchianPeriod)]+low[ArrayMinimum(low,bar,DonchianPeriod)])/2;
            break;

         case HIGH_LOW_CLOSE:
            SsMax=(close[ArrayMaximum(close,bar,DonchianPeriod)]+high[ArrayMaximum(high,bar,DonchianPeriod)])/2;
            SsMin=(close[ArrayMinimum(close,bar,DonchianPeriod)]+low[ArrayMinimum(low,bar,DonchianPeriod)])/2;
            break;

         case OPEN_HIGH_LOW:
            SsMax=open[ArrayMaximum(open,bar,DonchianPeriod)];
            SsMin=open[ArrayMinimum(open,bar,DonchianPeriod)];
            break;

         case CLOSE_HIGH_LOW:
            SsMax=close[ArrayMaximum(close,bar,DonchianPeriod)];
            SsMin=close[ArrayMinimum(close,bar,DonchianPeriod)];
            break;
        }


Developing a Trading System

When developing a strategy, we need to take into account not only false breakouts, but also the fact that the Donchian channel is most often used in trend strategies. The entry signal is formed by the channel breakout, therefore, in order to eliminate false exits outside channel borders, we need to use at least one trend indicator for signal confirmation. We also need to determine exact conditions for entry, open position management, exit, and money management. Let us formulate the above conditions.

1. A confirmation signal

The purpose of the article is not only to show examples of trading based on Donchian channels, but also to analyze them in terms of "survivability" in modern markets. Therefore, let us select a few confirmation indicators. Each of these indicators will form a tandem with the Donchian Channel. Thus we obtain several trading strategies based on the analyzed underlying strategy. To create tandems, I selected three confirmation signals from the following indicators:

  • Average Directional Movement Index (ADX). A combination with this signal will allow us to evaluate the state and strength of the current trend, and then enter into the market upon the breakout of the channel borders.
  • Moving Average Convergence/Divergence (MACD). MACD will monitor the current trend. When the price breaks the channel borders, we will check if this breakout is in the market direction or it is an accidental price spike (a false breakout).
  • The third confirmation will be generated by two indicators: Average Speed (the average price change speed in points/min) and X4Period_RSI_Arrows (a semaphore indicator consisting of four RSIs with different periods).

2. Formalizing trading systems

We need to find common parameters for these three strategies: let us select them so as to provide the maximum possible testing period. Therefore, let us define the parameters that will be controlled during testing:

  • Timeframe. The timeframe selection option will allow us to test the strategies on different time periods, which can characterize specific market phases, including weak movement and correction, as well as long trends, which may be obvious on higher periods.
  • Money Management. Several position sizing options depending on trade results will allow us to reveal whether re-investing is efficient or if it is more convenient to trade a fixed lot.
  • Open Position Management. Several options of managing an open position will help us determine the profit as the percentage of the current favorable movement that we can fix.
  • Indicator Parameters. Testing of selected strategies in different modes will help us find optimal parameters, with which our system will be efficient, as well as detect parameters that can make our system unprofitable.

Next, we need to formulate entry conditions for our trading strategies:

#1. Donchian Channel + ADX.

Conditions for the system:

  • The price breaks the upper or lower border of the Donchian channel.
  • The main line of the ADX trend strength must be above the pre-set ADX Level.
  • If the price breaks the channel border upwards, the DI+ line must be above DI-. DI- must be above DI+, if downwards.

Fig.2. Market entry conditions of the strategy Donchian channel+ADX

#2. Donchian Channel + MACD.  

Conditions for the system:

  • The price breaks the upper or lower border of the Donchian channel.
  • Also, the histogram value is above zero and above the signal line for buying.
  • The histogram value is below zero and below the signal line for selling.

Fig.3. Market entry conditions of the strategy Donchian channel+MACD

#3. Donchian Channel + (Average Speed and X4Period_RSI_Arrows).

Here are the system conditions:

  • The price breaks the upper or lower border of the Donchian channel.
  • The value of Average Speed must be greater than 1, and the semaphore RSI must mark at least 2 points above the candlestick for selling or below the candlestick for buying.

Fig.4. Market entry conditions of the strategy Donchian channel+(Average Speed and X4Period_RSI_Arrows)

Implementing a Trading Strategy

For the convenience of testing and optimization, all this types of strategies will be implemented in one Expert Advisor. The EA parameters will provide a selection of four strategies:

//+------------------------------------------------------------------+
//|  Declaration of enumerations of strategy types                   |
//+------------------------------------------------------------------+
enum Strategy
  {
   Donchian=0,
   Donchian_ADX,
   Donchian_MACD,
   Donchian_AvrSpeed_RSI
  };

  • Donchian — a breakout strategy only using the Donchian channel.
  • Donchian_ADX — a strategy with the ADX trend strength indicator used as a filter.
  • Donchian_MACD — a strategy with the MACD oscillator used as a filter.
  • Donchian_AvrSpeed_RSI — a strategy with the price rate of change and the semaphore RSI with different periods used as the filter.

Then we declare types of extreme values used for the Donchian channel, which we want to test:

//+------------------------------------------------------------------+
//| Declaration of enumerations of extreme types                     |
//+------------------------------------------------------------------+
enum Applied_Extrem
  {
   HIGH_LOW,
   HIGH_LOW_OPEN,
   HIGH_LOW_CLOSE,
   OPEN_HIGH_LOW,
   CLOSE_HIGH_LOW
  };

In addition, the Expert Advisor will provide for the possibility to use three money management systems:

//+------------------------------------------------------------------+
//|  Enumeration for lot calculation types                           |
//+------------------------------------------------------------------+
enum MarginMode
  {
   FREEMARGIN=0,     //MM Free Margin
   BALANCE,          //MM Balance
   LOT               //Constant Lot
  };

  • FREEMARGIN — calculating the basic lot based on the free margin.
  • BALANCE — lot calculation based on the current balance.
  • LOT — fixed lot. It is a manually specified basic lot.

Open positions will be managed by a system based on the Universal Trailing Stop Expert Advisor. On its basis, the CTrailing class was developed, which is located in the Trailing.mqh file.

Position managing methods and input parameters are given below:

enum   TrallMethod
  {
   b=1,     //Based on candlestick extrema
   c=2,     //Using fractals
   d=3,     //Based on the ATR indicator
   e=4,     //Based on the Parabolic indicator
   f=5,     //Based on the MA indicator
   g=6,     //% of profit
   i=7,     //Using points
  };


//--- Trailing Stop parameters

input bool                 UseTrailing=true;                            //Use of trailing stop
input bool                 VirtualTrailingStop=false;                   //Virtual trailing stop
input TrallMethod          parameters_trailing=7;                       //Trailing method

input ENUM_TIMEFRAMES      TF_Tralling=PERIOD_CURRENT;                  //Indicator timeframe

input int                  StepTrall=50;                                //Trailing step (in points)
input int                  StartTrall=100;                              //Minimum trailing profit (in points)

input int                  period_ATR=14;                               //ATR period (method #3)

input double               step_PSAR=0.02;                              //PSAR step (method #4)
input double               maximum_PSAR=0.2;                            //Maximum PSAR (method #4)

input int                  ma_period=34;                                //MA period (method #5)
input ENUM_MA_METHOD       ma_method=MODE_SMA;                          //Averaging method (method #5)
input ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE;                   //Price type (method #5)

input double               PercentProfit=50;                            //Percent of profit (method #6)

For a more convenient display of selected parameters during visual testing and demo operation, I have added a panel using information provided in the Graphical Interfaces series. It provides the main type of selected settings:

  • Type of strategy
  • Type of trailing stop
  • Type of money management
  • Take Profit
  • Stop Loss

For the display, the CDonchianUI class was developed, which is available in the file DonchianUI.mqh. If desired, you can add your own values. The panel is shown in Fig.5.

Fig.5. Information panel with the main modes of Donchian Expert.

Testing

Before launching the testing, we need to determine its conditions. The basic conditions are summarized in the below table:

Parameter Value
Testing interval 01.03.2016 — 01.03.2017
Market EURUSD/GOLD-6.17
Execution Every tick based on real ticks
Initial Deposit 1000 USD
Leverage  1:500
Server MetaQuotes

The Expert Advisor is presented in the 4-in-1 format, so there is no need in describing the widest choice of all possible combinations of settings. Let us single out the main blocks of settings, which will be combined during testing, and some individual parameters from these blocks will be optimized. For better understanding, the below table provides the Expert Advisor modes that will be changed during testing:

Expert Advisor block Testing Modes
Money Management Fixed lot/Balance
Working Timeframe M30 - D1
Position Management Trailing Stop/None
Strategy Type Donchian/Donchian+ADX/Donchian+MACD/Donchian+Avr.Speed+RSI

I will explain why only 2 modes are used for Money Management: during testing, the deposit will only be loaded by our Expert Advisor, and only one position will exist at a time, so modes of Balance and Free margin will actually be the same. 

1. The Donchian Channel trading strategy.

We start with the strategy using purely Donchian channels.


Fig. 6. The Donchian trading strategy on EURUSD.

During strategy testing and optimization on EURUSD, we made the following conclusions:

  • In the given range, the best results were obtained on M30-H1.
  • The indicator operation timeframe was set to 10-12.
  • In terms of the price used, the best results were obtained in the CLOSE_HIGH_LOW mode.
  • The efficiency of the trailing stop function was very low compared to the mode without it.
  • The general conclusion: A strategy based only on the Donchian channel behaved as a classical trend strategy, having a series of profitable trades during strong market movements.
//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_M30;                 //Working timeframe
input bool                 InfoPanel=false;                             //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=10;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian;                        //The selected strategy

//--- Trailing Stop parameters

input bool                 UseTrailing=false;                           //Use of trailing stop


As compared with the currency pair, testing on the GOLD-6.17 futures with the same period and timeframes - M30-H1, produced better results. 


Fig.7. The Donchian trading strategy on GOLD-6.17.

//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_M30;                 //Working timeframe
input bool                 InfoPanel=false;                             //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=12;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian;                        //The selected strategy
....

//--- Trailing Stop parameters

input bool                 UseTrailing=true;                            //Use of trailing stop
input bool                 VirtualTrailingStop=false;                   //Virtual trailing stop
input TrallMethod          parameters_trailing=7;                       //Trailing method

input ENUM_TIMEFRAMES      TF_Tralling=PERIOD_CURRENT;                  //Indicator timeframe

input int                  StepTrall=50;                                //Stop level trailing step (in points)
input int                  StartTrall=100;                              //Minimum trailing profit (in points)

2. The Donchian Channel and ADX trading strategy.

After testing the strategy with ADX used to filter the Donchian channel signals, we made the following conclusions:

  • The EA executed less trades, which had been expected. 
  • The best working timeframe was again M30.
  • The percentage of profitable trades was higher.
  • The effective channel period was 18, and ADX period was 10.
  • Again, the most effective price for the channel was CLOSE_HIGH_LOW.


Fig.8. Donchian + ADX trading strategy on EURUSD.

//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_M30;                 //Working timeframe
input bool                 InfoPanel=false;                             //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=18;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian_ADX;                    //The selected strategy
//--- ADX indicator parameter

input int                  ADX_period=10;
input double               ADX_level=20;

Testing on futures showed that on the H1 timeframe, with the Donchian channel period equal to 10 and ADX period equal to 8, the results are similar to the previous strategy. Again, the best results were obtained when drawing the channel based on Close prices.


Fig.9. The Donchian + ADX trading strategy on GOLD-6.17.

//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_H1;                  //Working timeframe
input bool                 InfoPanel=false;                             //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=18;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian_ADX;                    //The selected strategy
//--- ADX indicator parameter

input int                  ADX_period=8;
input double               ADX_level=20;

//--- Trailing Stop parameters

input bool                 UseTrailing=true;                            //Use of trailing stop
input bool                 VirtualTrailingStop=false;                   //Virtual trailing stop
input TrallMethod          parameters_trailing=7;                       //Trailing method

input ENUM_TIMEFRAMES      TF_Tralling=PERIOD_CURRENT;                  //Indicator timeframe

input int                  StepTrall=50;                                //Trailing step (in points)
input int                  StartTrall=100;                              //Minimum trailing profit (in points)

3. The Donchian Channel and MACD trading strategy.

After testing the strategy with MACD used to filter the Donchian channel signals, we made the following conclusions:

  • Once again, the best results were obtained on the H1 timeframe.
  • Changing MACD parameters didn't have any serious effect.


Figure 10. Donchian + MACD trading strategy on EURUSD.

//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_H1;                  //Working timeframe
input bool                 InfoPanel=true;                              //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=16;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian_MACD;                   //The selected strategy

//--- MACD indicator parameters

input int                  InpFastEMA=12;                               //Fast EMA period
input int                  InpSlowEMA=26;                               //Slow EMA period
input int                  InpSignalSMA=9;                              //Signal SMA period
input ENUM_APPLIED_PRICE   InpAppliedPrice=PRICE_CLOSE;                 //Applied price

When tested with futures, the best result was obtained with the Donchian channel period equal to 10, as in the previous strategy. A version with the trailing stop function was more efficient, than without it.


Fig.11. The Donchian + MACD trading strategy on GOLD-6.17.

//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_M30;                 //Working timeframe
input bool                 InfoPanel=true;                              //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=10;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian_MACD;                   //The selected strategy

//--- MACD indicator parameters

input int                  InpFastEMA=12;                               //Fast EMA period
input int                  InpSlowEMA=26;                               //Slow EMA period
input int                  InpSignalSMA=9;                              //Signal SMA period
input ENUM_APPLIED_PRICE   InpAppliedPrice=PRICE_CLOSE;                 //Applied price

Before proceeding to the next strategy with a complex filter, we should draw an intermediate conclusion based on the above strategies using classical indicators. There was not much difference between the tested strategies on EURUSD. However, the ADX and MACD filters reduced the number of market entries and increased the final result. In connection with the specifics of the futures market and its volatility, which differs much from currency pairs, filtering of Donchian signals didn't provide changes. However, the total results on futures were much better compared to the currency pair.

4. The Donchian Channel and Average Speed+X4Period_RSI_Arrows.

By optimizing the strategy of the Donchian channel combined with complex filter, we confirmed the conclusions about the strategy use in different trading conditions. Due to the low volatility of futures, the selectivity of this strategy was too high.


Fig.12. Donchian + Average Speed+X4Period_RSI_Arrows on EURUSD.

//+------------------------------------------------------------------+
//| Expert Advisor input parameters                                  |
//+------------------------------------------------------------------+
sinput string              Inp_EaComment="Donchian Expert";             //EA comment
input double               Inp_Lot=0.01;                                //Basic lot
input MarginMode           Inp_MMode=LOT;                               //Money Management
input int                  Inp_MagicNum=555;                            //Magic
input int                  Inp_StopLoss=400;                            //Stop Loss (in points)
input int                  Inp_TakeProfit=600;                          //Take Profit (in points)
input int                  Inp_Deviation = 20;                          //Deviation
input ENUM_TIMEFRAMES      InpInd_Timeframe=PERIOD_H1;                  //Working timeframe
input bool                 InfoPanel=true;                              //Display of the information panel
//--- Donchian Channel System indicator parameters

input uint                 DonchianPeriod=12;                           //Channel period
input Applied_Extrem       Extremes=CLOSE_HIGH_LOW;                     //Type of extrema
//--- Selecting the strategy

input Strategy             CurStrategy=Donchian_AvrSpeed_RSI;           //The selected strategy

//--- Average Speed indicator parameters

input int                  Inp_Bars=1;                                  //Number of bars
input ENUM_APPLIED_PRICE   Price=PRICE_CLOSE;                           //Applied price
input double               Trend_lev=2;                                 //Trend level
//--- The x4period_rsi_arrows indicator parameters

input uint                 RSIperiod1=7;                                //Period of RSI_1
input uint                 RSIperiod2=12;                               //Period of RSI_2
input uint                 RSIperiod3=18;                               //Period of RSI_3
input uint                 RSIperiod4=32;                               //Period of RSI_4
input ENUM_APPLIED_PRICE   Applied_price=PRICE_WEIGHTED;                //Applied price
input uint                 rsiUpperTrigger=62;                          //Overbought level
input uint                 rsiLowerTrigger=38;                          //Oversold level
//--- Trailing Stop parameters

input bool                 UseTrailing=false;                           //Use of trailing stop

Summary

After testing the trading system based on the Donchian channel, we made the following conclusions and notes about the strategy features:

  • Trading based on the channel behaves as a classical trend following strategy, and it can be improved by using additional filters.
  • Testing results were better on the futures market.
  • Unlike the classical calculation of the channel borders based on Highs and Lows, the CLOSE_HIGH_LOW (close prices) showed better results. This is connected with the testing symbol — the EURUSD market is characterized with price spikes in the form of long shadows. Such spikes distort channel borders, while close prices tend to be more objective.
  • Also, the best results were obtained on timeframes М30 — H1, not daily ones.
  • And the effective period ranges from 10 to 20 candlesticks.

Conclusion

The archive attached below contains all described files properly sorted into folders. For a correct operation, you should save the MQL5 folder to the terminal's root directory. We also used a graphical interface library EasyAndFastGUI, which is available in the related article.

Programs used in the article:

#
 Name
Type
Description
1
DonchianExpert.mq5 Expert Advisor
 A complex Expert Advisor combining 4 strategies based on the Donchian Channel.
2
DonchianUI.mqh Code Base  The GUI class
3
TradeFunctions.mqh Code Base  The class of trade functions.
4
Trailing.mqh Code Base  Open position management class.
5
average_speed.mq5 Indicator  Indicator of the average price change speed.
6
donchian_channels_system.mq5 Indicator  The Donchian Channel displaying candlesticks that break the channel borders.
7 x4period_rsi_arrows.mq5 Indicator  A semaphore indicator containing four RSIs with different period.