How is RSI calculated by Kite? Discrepancy observed on kite website

abokade
I tried calculating RSI based on explanation https://zerodha.com/varsity/chapter/indicators-part-1/
I took the closing price of SUZLON on daily time frame from 21-12-22 to 9-01-23. The RSI value is coming out to be 50 in calculation but on kite chart its showing 52.0. I tried with multiple scripts but same discrepancy is observed.
Tagged:
  • tonystark
    Could you post code that resulted in these values?

    Make sure to use double precision floating points while doing the calculations.
  • abokade
    @tonystark This is the code I wrote in C#:

    public static double CalculateRsi(IEnumerable closePrices, int interval)
    {

    var prices = closePrices as double[] ?? closePrices.ToArray();

    double sumGain = 0;
    double sumLoss = 0;

    for (int i = 1; i < prices.Length; i++)
    {
    var difference = prices[i] - prices[i - 1];
    if (difference >= 0)
    {
    sumGain += difference;
    }
    else
    {

    sumLoss -= difference;
    }


    }

    var averageGain = sumGain / 14;
    var averageLoss = sumLoss / 14;

    var relativeStrength = averageGain / averageLoss;
    double rsi = 100 - (100 / (1 + relativeStrength));

    return rsi;

    }
  • tonystark
    tonystark edited January 2023
    I think this tradingqna thread answers your question. To quote, Varsity is showing a simple average, I assume to simplify the example calculations, and Charts/Excel takes smoothed average.

    For reference ChartIQ documentation: https://documentation.chartiq.com/tutorial-Using%20and%20Customizing%20Studies%20-%20Definitions.html#rsi
Sign In or Register to comment.