Skip to content
All library documents

Calculating Rolling Aroon Up and Down Indicators

Article Quant Q&A · Author: xkcd

Summary

The document discusses how to calculate Aroon Up and Aroon Down from rolling windows of high and low prices. The period parameter sets the lookback window: for each observation, the calculation identifies where the highest high or lowest low occurred, measures the elapsed bars since that extreme, and scales the remaining portion of the window to a percentage. An accepted answer presents a window-based implementation and separate searches for the maximum high and minimum low.

The examples show why indexing and window boundaries matter: the initial attempt processes disjoint chunks and uses integer arithmetic, while the alternative computes successive rolling observations and uses a floating-point scale. The page also includes another implementation and suggests using a technical-analysis library. It offers code examples rather than a comparison against reference outputs, and details such as warm-up observations and tie handling may differ between implementations. Traders adapting the indicator should confirm the precise lookback convention used by their data or library.

Key ideas

  • The period parameter defines the lookback window used to find recent price extremes.
  • Aroon Up and Down measure the age of the window’s highest high and lowest low as scaled percentages.
  • A rolling calculation evaluates a fresh lookback window at each observation.
  • Window endpoints, initial observations, arithmetic types, and equal extremes can affect implementation results.
  • A technical-analysis library can provide a reference implementation, but its conventions should be checked.

Tags

Full text
# Technical analysis - Calculating Aroon Indicator Serie


# Technical analysis - Calculating Aroon Indicator Serie












I'm trying to build a class to create Aroon series. But it seems I don't understand the steps well. I'm not sure about what purpose I have to use the period parameter.

Here is my first attempt:

```
/// <summary>
/// Aroon
/// </summary>
public class Aroon : IndicatorCalculatorBase
{
    public override List<Ohlc> OhlcList { get; set; }
    public int Period { get; set; }

    public Aroon(int period) 
    {
        this.Period = period;
    }

    /// <summary>
    /// Aroon up: {((number of periods) - (number of periods since highest high)) / (number of periods)} x 100
    /// Aroon down: {((number of periods) - (number of periods since lowest low)) / (number of periods)} x 100
    /// </summary>
    /// <see cref="http://www.investopedia.com/ask/answers/112814/what-aroon-indicator-formula-and-how-indicator-calculated.asp"/>
    /// <returns></returns>
    public override IIndicatorSerie Calculate()
    {
        AroonSerie aroonSerie = new AroonSerie();

        int indexToProcess = 0;

        while (indexToProcess < this.OhlcList.Count)
        {
            List<Ohlc> tempOhlc = this.OhlcList.Skip(indexToProcess).Take(Period).ToList();
            indexToProcess += tempOhlc.Count;

            for (int i = 0; i < tempOhlc.Count; i++)
            {   
                int highestHighIndex = 0, lowestLowIndex = 0;
                double highestHigh = tempOhlc.Min(x => x.High), lowestLow = tempOhlc.Max(x => x.Low);
                for (int j = 0; j < i; j++)
                {
                    if (tempOhlc[j].High > highestHigh)
                    {
                        highestHighIndex = j;
                        highestHigh = tempOhlc[j].High;
                    }

                    if (tempOhlc[j].Low < lowestLow)
                    {
                        lowestLowIndex = j;
                        lowestLow = tempOhlc[j].Low;
                    }
                }

                int up = ((this.Period - (i - highestHighIndex)) / this.Period) * 100;
                aroonSerie.Up.Add(up);

                int down = ((this.Period - (i - lowestLowIndex)) / this.Period) * 100;
                aroonSerie.Down.Add(down);
            }
        }

        return aroonSerie;
    }
}
```

Is there anyone else tried to do that before? Here is a few reference points about the indicator:

- http://www.investopedia.com/ask/answers/112814/what-aroon-indicator-formula-and-how-indicator-calculated.asp

- http://www.investopedia.com/articles/trading/06/aroon.asp

- http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:aroon

## Answer by Old Fox (score 2, accepted)

https://quant.stackexchange.com/a/17529

I answered @Anilca's question in SO (and the answer was accepted)

I summarize my answer with the working solution:

```
public class Aroon : IndicatorCalculatorBase
{

    public override List<OhlcSample> OhlcList { get; set; }
    private readonly int _period;

    public int Period
    {
        get { return _period; }
    }

    public Aroon(int period)
    {
        _period = period;
    }

    public override IIndicatorSerie Calculate()
    {
        var aroonSerie = new AroonSerie();
        for (var i = _period; i < OhlcList.Count; i++)
        {

            var aroonUp = CalculateAroonUp(i);
            var aroonDown = CalculateAroonDown(i);

            aroonSerie.Down.Add(aroonDown);
            aroonSerie.Up.Add(aroonUp);
        }

        return aroonSerie;
    }

    private double CalculateAroonUp(int i)
    {
        var maxIndex = FindMax(i - _period, i);

        var up = CalcAroon(i - maxIndex);

        return up;
    }

    private double CalculateAroonDown(int i)
    {
        var minIndex = FindMin(i - _period, i);

        var down = CalcAroon(i - minIndex);

        return down;
    }

    private double CalcAroon(int numOfDays)
    {
        var result = ((_period - numOfDays)) * ((double)100 / _period);
        return result;
    }

    private int FindMin(int startIndex, int endIndex)
    {
        var min = double.MaxValue;
        var index = startIndex;
        for (var i = startIndex; i <= endIndex; i++)
        {
            if (min < OhlcList[i].Low)
                continue;

            min = OhlcList[i].Low;
            index = i;
        }
        return index;
    }

    private int FindMax(int startIndex, int endIndex)
    {
        var max = double.MinValue;
        var index = startIndex;
        for (var i = startIndex; i <= endIndex; i++)
        {
            if (max > OhlcList[i].High)
                continue;

            max = OhlcList[i].High;
            index = i;
        }
        return index;
    }
}
```

P.S

Guys, i usually active at SO... if anyone need clarifications, please ask in the source question (and feel free to do this)

## Answer by John (score 0)

https://quant.stackexchange.com/a/17506

```
 public class Aroon
    {
        public bool AroonDown
        {
            get;
            set;
        }
        public double Period
        {
            get;
            set;
        }
        public Aroon()
        {
        }
        public Aroon(double period)
        {
            Period = period;
        }
        public IList<double> Execute(IList<double> src)
        {
            if (!this.AroonDown)
            {
                return this.ExecuteUp(src);
            }
            return this.ExecuteDown(src);
        }
        public IList<double> ExecuteDown(IList<double> src)
        {
            double[] period = new double[src.Count];
            for (int i = 0; i < src.Count; i++)
            {
                double num = IndUtil.LowestBarNum(src, i, Period);
                period[i] = 100 * (Period - num) / Period;
            }
            return period;
        }
        public IList<double> ExecuteUp(IList<double> src)
    {
        double[] period = new double[src.Count];
        for (int i = 0; i < src.Count; i++)
        {
            double num = IndUtil.HighestBarNum(src, i, Period);
            period[i] = 100 * ((Period - num) / Period);
        }
        return period;
    }
    }

    public class IndUtil
    {
      public static double  HighestBarNum(IList<double> src, int i, double Period)
        {
             int maxIndex = -1;
         double maxValue = Double.MinValue; // Immediately overwritten anyway

            int index = 0;

            int srccount = src.Count();
            var mincount = Math.Min(i + Period, srccount);

            for (int k = i; k < mincount; k++)
            {
                double value = src[k];
                if (value.CompareTo(maxValue) > 0 || maxIndex == -1)
                {
                    maxIndex = index;
                    maxValue = value;
                }
                index++;
            }
            return maxIndex;
        }
      public static double LowestBarNum(IList<double> src, int i, double Period)
      {
          int minIndex = -1;
          double minValue = Double.MaxValue; // Immediately overwritten anyway

          int index = 0;

           int srccount=src.Count();
           var mincount = Math.Min(i + Period, srccount);
          for (int k = i; k < mincount; k++)
          {

              double value = src[k];
              if (value.CompareTo(minValue) < 0 || minIndex == -1)
              {
                  minIndex = index;
                  minValue = value;
              }
              index++;
          }
          return minIndex;
      }
    }
```

## Answer by xgdgsc (score 0)

https://quant.stackexchange.com/a/17511

AROON Indicator is a built-in function in TA-lib, you should try it first rather than implement it yourself.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.