## Saturday, June 20, 2009

### Aroon Indicator / Oscillator

Aroon Indicator AI
Read on for formula, calculation step and VBA Code. The Aroon oscillator is elaborated after the Aroon Indicator. For naive backtest results and findings, visit here.

The Aroon indicator is defined as such

Aroon Up is the number of days it took out of n days to achieve the High in the same n days / n

Aroon Down is the number of days it took out of n days to achieve the Low in the same n days / n
, where n is specified by the user.

If today’s Close is the last e.g. 10 days’ High, Aroon Up for today is 100% indicating an uptrend. Aroon indicator assumes that record highs or lows are indicators of trend.

VBA Code
Method A uses functions, while Method B uses sub procedures to calculate the Aroon indicator. Method B is faster and more flexible.

Method A
I designed the AI function for the Aroon indicator to be an array function. To display the entire set of outputs, enter the APZ function into the one cell and select it along with the cell horizontally next to it, press F2 and Enter. Your inputs are the last n periods of prices.

'Paste this code into your ThisWorkBook code window in VBA. Right Click This WorkBook in Project Explorer and click View Code.
Private Sub Workbook_Open()
End Sub

'The rest belong to any module
'Tells Excel to includes these in list of functions, add descriptions to them and create a new category called Technical Indicators.
Application.MacroOptions macro:="AI", _
Description:="Returns the Aroon Up and Aroon Down indicators" & Chr(10) & Chr(10) & _
"Input n periods of prices.", _
Category:="Technical Indicators"
End Sub

Public Function AI(prices)
max1 = WorksheetFunction.Max(prices)
min1 = WorksheetFunction.Min(prices)
n = WorksheetFunction.Count(prices)
Dim result(0, 1 To 2)
result(0, 1) = WorksheetFunction.Match(max1, prices, 0) / n
result(0, 2) = WorksheetFunction.Match(min1, prices, 0) / n
AI = result
End Function

Once you are done with the above, enter into any cell "=AI([n periods of prices])", select the cell and the one next to it, press F2 and Enter, to view the Aroon Up and Aroon Down indicators.

Method B
To run Method B, you have to copy the Runthis sub from the page on Accumulation/Distribution line into your module. You will run the AI sub from the Runthis sub.

'Copy the following line into the Runthis sub
'Just before the line End Sub
'Disable all other macros that Runthis will call e.g. CLV, ADL, by
'marking them out as comments with single quotes

AI_1 close1, output, n

Sub AI_1(close1 As Range, output As Range, n As Long)
prices1 = Range(close1(1, 1), close1(n, 1)).Address(False, False)
output(0, 1).Value = "Aroon Up"
output(n, 1).Value = "=match(max(" & prices1 & ")," & prices1 & ",0)/" & n
output(n, 1).Copy output
output(0, 2).Value = "Aroon Down"
output(n, 2).Value = "=match(min(" & prices1 & ")," & prices1 & ",0)/" & n
output(n, 2).Copy output.Offset(0, 1)
Range(output(1, 1), output(n - 1, 2)).Clear
End Sub

Other References

The Aroon oscillator is calculated as shown below. Due to its computational simplicity, I decided not to write any code on the Aroon oscillator. Instead, the Aroon oscillator can be calculated from the AI function for the Aroon Indicator.

Aroon Oscillator = 100 x Aroon Up - 100 x Arron Down

A positive value represents an uptrend and vice versa.

Other References

Like what you have just read? Digg it or Tip'd it.
The objective of Finance4Traders is to help traders get started by bringing them unbiased research and ideas. Since late 2005, I have been developing trading strategies on a personal basis. Not all of these models are suitable for me, but other investors or traders might find them useful. After all, people have different investment/trading goals and habits. Thus, Finance4Traders becomes a convenient platform to disseminate my work...(Read more about Finance4Traders)