Donchian Channel 3 (3 ways to display the trend)

Category: Indicators By: Nicolas Created: September 17, 2019, 8:38 AM
September 17, 2019, 8:38 AM
Indicators
5 Comments

This is the Donchian Channel indicator extended version.

You can choose to display the trend in 3 different ways:

  1. traditional one by applying the indicator directly onto the price chart to display the channel formed by the higher highs and lower lows
  2. as a normalized price oscillator with normalized boundaries at 1/-1 (calculated upon the last higher highs and lower lows)
  3. as a normalized price oscillator with dynamic boundaries

The current trend is displayed as a red/green plotted at zero level. The trend change each time the price broke the higher or lower boundaries of the donchian channel.

Indicator converted from mt4 code following a request made in the Italian indicator forum.

//PRC_DonchianChannel3 | indicator
//17.09.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//translated from mt4 version

// --- settings 
ChannelPeriod           = 21
HighLowShift            = 1
ShowMiddle              = 1 //1=true;0=false
ZeroBind                = 1 //1=true;0=false
Normalize               = 1 //1=true;0=false
// --- end of settings 

cprice = customclose
dcUpper  = Highest[ChannelPeriod](high)[HighLowShift]
dcLower  = Lowest[ChannelPeriod](low)[HighLowShift]
dcMiddle = (dcUpper+dcLower)/2.0

if (ZeroBind) then
 if (Normalize) then
  buffer1 =  1
  buffer2 = -1
  diff = (dcUpper-dcMiddle)
  if (diff <> 0) then
   price = (cprice-dcMiddle)/diff
  else
   price = 0
  endif
 else
  buffer1 = dcUpper-dcMiddle
  buffer2 = dcLower-dcMiddle
  price = (cprice-dcMiddle)
 endif
else
  buffer1 = dcUpper
  buffer2 = dcLower
  price = cprice
endif

trendp  = trendp[1]
trend   = trend[1]

if (dcUpper>dcUpper[1]) then
t rend =  1
endif
if (dcLower<dcLower[1]) then
t rend = -1
endif

buffer3=undefined
if (ShowMiddle) then
 if (ZeroBind) then
  buffer3 = 0
 else
  buffer3 = (buffer1+buffer2)/2
 endif
endif
if (cprice>dcUpper) then
 trendp =  1
endif
if (cprice<dcLower) then
 trendp = -1
endif
if (cprice<dcUpper and cprice>dcLower) then
 trendp =  0
endif

if trend>0 then
 r=0
 g=128
else
 r=255
 g=0
endif


return buffer1 coloured(0,128,0) style(dottedline,1),buffer2 coloured(255,0,0) style(dottedline,1),buffer3 coloured(r,g,0) style(line,2),price coloured(0,191,255) style(line,3) //,buffer4

 

Download
Filename: PRC_DonchianChannel3.itf
Downloads: 310
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Logo Logo
Loading...