Summary: This indicator script helps to determine whether the underlying symbol is trending or in a trading range. Calculation: The number of bars since the most recent high in an n-period window. Range: 0 To 100 Developer: Tushar S. Chande Interpretation: 1. Trending: When the indicator script reaches 70 to 100 the underlying indicator is in an upwards trend. 2. Trading Range: When the indicator script reaches 0 the underlying indicator isn't in an upwards trend. (But it could be in a downwards trend).
' Assign the parameters to script variables. _indicatorKey = indicatorKey _periods = periods
' Get the underlying indicator values, indexed by bar index. Define values() As Number = IndicatorValues(_indicatorKey, barIndex, length + _periods) ' Use for the number of bars since the lowest value. Define barsFromHighest As Integer ' Use for the highest value in the window. Define highest As Number ' Use for the calculated Aroon Up values, indexed by bar index. Define results(length - 1) As Number ' Calculate the Aroon Up values for the specified bar range. For i As Integer = length - 1 To 0 Step -1 ' Calculate the Aroon Up value for the current bar. barsFromHighest = _periods highest = 0 For j As Integer = i + _periods To i Step -1 If (values(j) >= highest) Then barsFromHighest = j - i highest = values(j) End If Next ' Assign the Aroon Up value for the current bar. results(i) = ((_periods - barsFromHighest) / _periods) * 100 Next Return results