RSI on an array
Forums › ProRealTime English forum › ProBuilder support › RSI on an array
- This topic has 5 replies, 3 voices, and was last updated 3 years ago by Vonasi.
-
-
03/10/2021 at 1:29 PM #16371303/10/2021 at 2:06 PM #163718
So you want to store values in an array and calculate the RSI of the latest 14 of them?
You would need to use a loop to look at lastset down to lastset-13 values and calculate the RSI using these values. You could not use the RSI instruction as that looks at the last 14 bars values.
Using arrays is only necessary if you are not storing a new value at every bar.
1 user thanked author for this post.
03/10/2021 at 2:08 PM #163719No, because an array is made of several elements, which one should be used?
You can use only, say, element 12 indirectly:
12Element = $myArray[12]myRSI = RSI[14](Element)1 user thanked author for this post.
03/10/2021 at 5:00 PM #163738Here is an example of how we can store values in an array and then do calculations on the last ‘p’ array locations. This example calculates the RSI of the last 14 high fractals. Unfortunately it is just a simple average based RSI and not smoothed as I believe the normal RSI is (I couldn’t figure out the how to do that calculation in the time I had!)
123456789101112131415161718192021222324252627p = 14if high < high[1] and high[1] > high[2] thena = a + 1$myarray[a] = high[1]endifup = 0down = 0if a >=14 thenfor b = lastset($myarray) downto lastset($myarray)-13if $myarray[b] > $myarray[b-1] thenup = up + ($myarray[b] - $myarray[b-1])endifif $myarray[b] < $myarray[b-1] thendown = down + ($myarray[b-1] - $myarray[b])endifnextupavg = up/pdownavg = down/prs = upavg/downavgmyrsi = 100-(100/(1+rs))endifreturn myrsi1 user thanked author for this post.
03/10/2021 at 11:21 PM #163756Thanks a lot, both of you!
Vonasi, it worked. I had the array code covered (I did an average from it, I believe I learned from your code somewhere from the forum as well), but it saved a lot of time with the RSI-calculation.
So thanks again.
03/10/2021 at 11:48 PM #163758Thanks for the thanks – but it is not an RSI calculation that returns the same result as the built in platform RSI. I tested it using every close value (which would be the same as the built in platform RSI uses) and the result was different because I believe the normal RSI either uses smoothing by doing the following:
The second, and subsequent, calculations are based on the prior averages and the current gain loss:
-
Average Gain = [(previous Average Gain) x 13 + current Gain] / 14.
-
Average Loss = [(previous Average Loss) x 13 + current Loss] / 14.
Borrowed from:
https://school.stockcharts.com/doku.php?id=technical_indicators:relative_strength_index_rsi
I’ve got rather a lot on at the moment (like trying to sort out a Greek biometric residency permit due to bloody Brexit) which is taking up a lot of time right now otherwise I would have persisted with the calculations – sorry but hopefully I put you on the right path.
1 user thanked author for this post.
-
-
AuthorPosts
Find exclusive trading pro-tools on