Saturday, September 04, 2010

Donchian Channel Upper [DCU]

Descripton
Summary:
This indicator script measures the highest  price of an underlying symbol in a specified number of periods.

Calculation:
The highest high in a specified number of periods of the underlying symbol.

Developer:
Richard Donchian

Interpretation: 
1. Resistance: When the underlying symbol is moving upwards towards the indicator script, the underlying symbol is likely to reverse direction and move downwards.
2. Resistance Broken: When the underlying symbol breaks resistance by crossing above the indicator script, the underlying symbol is likely to continue moving upwards.


Variables
TypeIdentifierDescription
Integer_symbolIndexUse for the underlying symbol on which to calculate the Donchian Channel Upper.
Integer_periodsUse for the number of periods to include in the Donchian Channel Upper calculation.

OnInitialize
Initialize
Function Parameters
TypeIdentifierDescription
SymbolsymbolIndexUse for the underlying symbol on which to calculate the Donchian Channel Upper.
IntegerperiodsUse for the number of periods to include in the Donchian Channel Upper calculation. [Default 10]
Implementation
	 ' Assign the parameter to script variables.
	_symbolIndex = symbolIndex
	_periods = periods

OnValues
Function Parameters
TypeIdentifierDescription
IntegerbarIndex
Integerlength
Implementation
	 ' Get the highest prices of the symbol, indexed by bar index. 
	Define high() As Number = BarHigh(_symbolIndex, barIndex, length + _periods)
	Define max As Number
	 ' Use for the calculated Donchian Channel Upper values, indexed by bar index.
	Define results(length - 1) As Number
	 ' Calculate the Donchian Channel Upper values for the specified bar range.
	For i As Integer = length - 1 To 0 Step -1
		max = 0
		 ' Calculate the Donchian Channel Upper value for the current bar.
		For j As Integer = i + _periods - 1 To i Step -1
			If (high(j) > max) Then
				max = high(j)
			End If
		Next
		results(i) = max
	Next
	Return results

Copyright © 2010 IQBroker, LLC. All rights reserved.