DYO: Average True Range Bands


Q:  I have a request to write a DYO that paints price bars red or green based on the swing concepts described below.  The decision to color the bars red or green is based on an Average True Range (ATR) function off the highs or lows over the last x bars.

Inputs:   BarLength(16) – The number of bars to look back to determine the highest high/low.

             AtrLength(9) – The number of bars to use when calculating the Average True Range. 

Add to the lowest low of the last 16 bars,  2.5 average true range function (AtrLength(9))  green bars when above.  Subtract from the highest high of the last 16 bars, 2.5 average true range function (AtrLength(9)  red bars when below.  If you were to plot the indicator that makes the red green red pattern,it would look very similar to a parabolic.  When the price is above the line, the bars are green, when it is below it, the bars are red.   Thank you for taking my request into consideration

 

A:

Template:  1304-TrueRangeBands

 

I was left to guess that it is the bar High being above the upper trigger that makes the bar green, and the bar Low being below the lower trigger that makes the bar red.   You can uncheck the Show box on Line E and Line G to remove the visual of the trigger levels.

Line A is the 9 period Average True Range, and Line B multiplies this by 2.5 and stores in [2].   Line C and D find the range extremes for the prior 16 bars.  Line E calculates the upper ATR band by adding to the Min Low the ATR*2.5.   Line F is the color bar test for this band being exceeded by a high.  Line G calculates the lower ATR band by subtracting from the Max High the ATR*2.5.   Line H is the color bar test for this band being exceeded by a low.

Template:  1304-TrueRangeBands


Last modified 1/17/08 5:37 PM