# Relative Strength Indicator. (UDF -vba)

#### wheelie pete

##### New Member
Afternoon - I searched the forums and couldn't come up with anything, but I'm wondering if anyone could help modify this code that I found on another site, so that it would take into account the average of one of the functions of the previous cells. Effectively, I'm trying to modify this code

Code:
``````Function RSI(MyCells As Range)
Dim up_day, down_day, ups, downs
Dim average_up, average_down
Dim RS, cellcount As Long
Dim cll As Range
ups = 0
up_day = 0
downs = 0
down_day = 0
cellcount = 0
For Each cll In MyCells
cellcount = cellcount + 1
If cellcount = MyCells.Count Then Exit For
If cll.Value >= cll.Offset(1, 0).Value Then
downs = downs + cll - cll.Offset(1, 0).Value
ElseIf cll.Value < cll.Offset(1, 0).Value Then
ups = ups + cll.Offset(1, 0).Value - cll.Value
End If
Next cll
average_up = ups / cellcount
average_down = downs / cellcount

RS = average_up / average_down

RSI = 100 - (100 / (1 + RS))

End Function``````

So that it takes into account the average of previous averages as shown on this page.

https://stockcharts.com/school/doku...hnical_indicators:relative_strength_index_rsi

Any takers on this? I believe it needs an array, but I'm just not sure. Thanks!! pete

Last edited by a moderator:

### Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Replies
0
Views
189
Replies
16
Views
709
Replies
19
Views
671
Replies
4
Views
171
Replies
1
Views
149