Thursday, August 18, 2011

sdi_atr - Average True Range In Chart Label

ATR (Average True Range) is a calculation that shows how much you might expect the given equity to move during the course of the next chart bar. Most chart packages will display ATR as a subgraph study. Now, to my mind, that's a lot of screen real estate to invest in a calculation for which I am mostly interested in the current value. In other words, I have little need to do technical analysis on ATR. So my ATR simply plots as a chart label in the upper left hand corner. Sometimes it is interesting to know if ATR is rising, flat or falling so I color code the label green, orange or red, respectively. Here is an image:


SPY with ATR in a label on upper left
 ##########################################################
# sdi_atr: Display Average True Range as a label
#hint: Displays the AverageTrueRange as a color-coded chart label. Red=decreasing, Orange=level, Green=increasing. Version:1.0
# source:http://www.smallDogInvestor.com
# author: allen everhart
# date: 10Mar2011
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.
declare UPPER ;
input length = 14 ;
def bar = avgTrueRange(high,close,low,length);
AddChartLabel(1,concat(concat(concat("ATR(",length), "):"), bar),
  if bar>bar[1] then
    color.GREEN
  else if bar== bar[1] then
    color.ORANGE
  else
    color.RED
);

#################




3 comments:

  1. Would it be possible to convert to TOS a Metastock code that places on a histogram a 20EMA on an ATR(20) which would show,visually, an increasing/decreasing volatility? The Metastock code, given in a webinar is :
    0-(ATR (20)- MOV(ATR(20),20,E))
    Thanks!

    ReplyDelete
  2. Found the code via a google search. Thanks anyway.

    ReplyDelete