2

When I calculate the SMA and EMA values using TA-lib for any period, the values are always equal. Does anyone else has any experience on this? Thanks.

Code for Ema (I just replace Core.Ema with Core.Sma for SMA):

            double[] output = new double[closePrices.Length];
            int begin;
            int length;

            Core.RetCode retCode = Core.Ema(closePrices.Length - 1, closePrices.Length - 1, closePrices, period, out begin, out length, output);

            if (retCode == Core.RetCode.Success)
            {
                for (int i = 0; i < length; i++)
                {
                    result = Math.Round(output[i], 5);
                }
            }

1 Answers1

0

Your starting index and ending index for the EMA method is the same. Change the starting index to 0.

Adrian Begi
  • 130
  • 10