Donchian

Description

The Donchian strategy is a technical indicator based on the Donchian channel, allowing for several levels of complexity. The current implementation and default values of this channel are presented by Oscar G. Cagigas in his article "The Degree of Complexity". 

In order to build the Donchian channel, the system registers the highest high and the lowest low price on two periods (by default, 40 and 15). The upper band value is equal to the highest high on the shorter period if there is a simulated short position; otherwise, the highest high on the longer period is used. The lower band uses the lowest low on the shorter period if there is a simulated long position; if the position is short or absent, the lowest price on the longer period is plotted instead.

At the lowest complexity level, the strategy adds simulated orders according to the following rules:

  • Buy To Open. The high price is greater than the previously calculated highest high on the longer period.

  • Sell To Open. The low price is less than the previously calculated lowest low on the longer period.

  • Buy To Close. The high price is greater than the previously calculated highest high on the shorter period.

  • Sell To Close. The low price is less than the previously calculated lowest low on the shorter period.

To increase the complexity of the system to the medium level, you can add either a volatility filter or an ATR-based stop loss. The volatility filter affects simulated entry orders: in addition to the previously described conditions, this filter enables checking whether the previous true range was less than its average value multiplied by a factor. The stop-loss affects simulated exit orders: for Sells, it checks whether the close price is less than the entry price minus the Average True Range (ATR) multiplied by the stop factor. For Buys, it's vice versa: the high price needs to exceed the entry price by the ATR multiplied by the stop factor. In order to set the strategy to the medium level, set either the atr factor or the atr stop factor to a non-zero value. If you prefer to use the highest complexity level, make sure both parameters are non-zero.  

Input Parameters

entry length The longer period, in bars.
exit length The shorter period, in bars.
atr length The number of bars used in the calculation of the Average True Range.
atr factor The factor used in the calculation of the volatility filter. Setting this parameter to zero will reduce the complexity of the system.
atr stop factor The factor used in the calculation of the stop loss. Setting this parameter to zero will reduce the complexity of the system.
atr average type The type of moving average to be used in the calculation of the Average True Range: simple, exponential, weighted, Wilder's, or Hull.

Plots

BuyStop The highest high on the longer period; displayed if there is no short position.
CoverStop The highest high on the shorter period; displayed if there is a short position.
ShortStop The lowest low on the longer period; displayed if there is no long position.
SellStop The lowest low on the shorter period; displayed if there is a long position.

Further Reading

1. "The Degree Of Complexity" by Oscar G. Cagigas. Technical Analysis of Stocks & Commodities, February 2014.