More Information about:
Link: 1) http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:average_true_range_a




Calculation:

True Range is the greatest of the following three values:

- difference between the current maximum and minimum (high and low);
-difference between the previous closing price and the current maximum;
- difference between the previous closing price and the current minimum.

The indicator of Average True Range is a moving average of values of the true range.


Source Code "Average True Range Technical Indicator (ATR)":

function init()
{
   ATR.createParameter("Period", 14);

   ATR.createBuffer("ATR");
   ATR.setBufferColor("ATR", 'lime');
   ATR.setBufferDrawStyle("ATR", DrawStyle.LINE);

   ATR.setAutoChangeMaxMin("ATR");
}

function start()
{
   ATR.label = "ATR(" + ATR.parameter("Period") + ")";

   var num = Shared.numberOfQuotes();

   var buf = new Array(num);

   buf[0] = Shared.high(0) - Shared.low(0);
   for (var i = 1; i < num; ++i) {
     var fHigh = Shared.high(i);
      var fLow = Shared.low(i);
      var fPrevClose = Shared.close(i - 1);

      var fVal = Math.max(fHigh, fPrevClose) - Math.min(fLow, fPrevClose);

     buf[i] = fVal;
   }
   ATR.setBufferData("ATR", Shared.sma(ATR.parameter("Period"), buf));
}