RSI on an array

Viewing 6 posts - 1 through 6 (of 6 total)
  • #163713

    Is it possible to calculate an RSI with values from an array? Something like:

     

    #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.
    #163719

    No, because an array is made of several elements, which one should be used?

    You can use only, say, element 12 indirectly:

     

    1 user thanked author for this post.
    #163738

    Here 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!)

     

    1 user thanked author for this post.
    #163756

    Thanks 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.

    #163758

    Thanks 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.
Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login