'**************************************************************
'*   Adaptive Price Zone Upper Band (APZUpper)
'*     by Jeremy Williams
'*	   August 22,2006
'*
'*	Adapted from Technical Analysis of Stocks and Commodities
'*     September 2006
'*
'*  Summary: 
'*
'*      This indicator returns and plots the Upper band around the
'*  double smoothed EMA. For more information see "Trading
'*  With An Adaptive Price Zone" in the August 2006 edition of
'*  Technical Analysis of Stocks and Commodities.
'*
'*  Parameters:
'*
'*  Periods= Specifies the number of Periods used for the EMA and
'*             average range calculations.
'*
'*  BandWidth= Specifies the number of deviations above/below the 
'*              double smoothed EMA used to calculate the Bands
'*
'************************************************************** 

#Indicator
#Param "Periods",5
#Param "BandWidth",2

Dim myUpper		As Single
Dim myEMA		As Single
Dim myDoubleEMA	As Single
Dim myRange 	As Single
Dim myRangeEMA	As Single
Dim myRangeDEMA As Single

' Find the EMA and the Double Smoothed EMA
myEMA = EMA(Periods)
myDoubleEMA = EMA(myEMA,Periods)

' Find the intraday range and average using a Double Smoothed EMA
myRange = High - Low
myRangeEMA = EMA(myRange,Periods)
myRangeDEMA = EMA(myRangeEMA,Periods)

' Caclulate the Upper bound
myUpper = myDoubleEMA + BandWidth*myRangeDEMA

' Plot the Upper band
PlotPrice("Upper",myUpper)

Return myUpper    ' Return the value of the Upper Band