Average True Range free

by qualitiedx2 in category Trend at 17/02/2012
Description

The range of a day's trading is simply high − low. The true range extends it to yesterday's closing price if it was outside of today's range. true range = max(high, close(prev) - min(low, close(prev) The true range is the largest of the: * Most recent period's high less the most recent period's low * Absolute value of the most recent period's high less the previous close * Absolute value of the most recent period's low less the previous close.

 Average True Range

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, ScalePrecision = 5, AccessRights = AccessRights.None)]
    public class AverageTrueRange : Indicator
    {
        private TrueRange _tri;

        [Parameter(DefaultValue = 14, MinValue = 2)]
        public int Period { get; set; }

        [Output("ATR", Color = Colors.Orange)]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {            
            _tri = Indicators.TrueRange();
        }

        public override void Calculate(int index)
        {
            if (index < Period + 1)
            {
                Result[index] = _tri.Result[index];
            }
            if (index >= Period)
            {
                Result[index] = (Result[index - 1]*(Period - 1) + _tri.Result[index])/Period;
            }
        }
    }
}
Comments
5