Relative Strength Indicator. (UDF -vba)

wheelie pete

New Member
Joined
Mar 1, 2019
Messages
6
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,005
Messages
6,122,661
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top