public static Pine Ema(Pine source, int period)
        {
            double[] emaValues = new double[source.Count];

            var sourceFix = source.ToArray();

            var sma = TA.Ema(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, emaValues);

            if (sma == TA.RetCode.Success)
            {
                return(emaValues.Take(outNbElement).ToPine());
            }

            throw new Exception("Could not calculate EMA!");
        }
        public static List <decimal> Linreg(List <decimal> source, int period = 14)
        {
            // int outBegIdx, outNbElement;
            double[] outValues = new double[source.Count];

            var sourceFix = source.Select(x => Convert.ToDouble(x)).ToArray();

            var ema = TA.LinearReg(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, outValues);

            if (ema == TA.RetCode.Success)
            {
                return(outValues.Take(outNbElement).Select(x => Convert.ToDecimal(x)).ToList());
            }

            throw new Exception("Could not calculate RSI!");
        }
        public static Pine Linreg(Pine source, int period = 14)
        {
            // int outBegIdx, outNbElement;
            double[] outValues = new double[source.Count];

            var sourceFix = source.ToArray();

            var ema = TA.LinearReg(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, outValues);

            if (ema == TA.RetCode.Success)
            {
                return(outValues.Take(outNbElement).ToPine());
            }

            throw new Exception("Could not calculate RSI!");
        }
        public static List <double> RSI(IEnumerable <double> source, int period)
        {
            // int outBegIdx, outNbElement;
            double[] rsiValues = new double[source.Count()];

            var sourceFix = source.ToArray();

            var ema = TA.Rsi(0, source.Count() - 1, sourceFix, period, out int outBegIdx, out int outNbElement, rsiValues);

            if (ema == TA.RetCode.Success)
            {
                return(rsiValues.Take(outNbElement).ToList());
            }

            throw new Exception("Could not calculate RSI!");
        }
        public static Pine Sma(Pine source, int period = 30)
        {
            // int outBegIdx, outNbElement;
            double[] smaValues = new double[source.Count];
            //List<double?> outValues = new List<double?>();

            var sourceFix = source.ToArray();

            var sma = TA.Sma(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, smaValues);

            if (sma == TA.RetCode.Success)
            {
                return(smaValues.Take(outNbElement).ToPine()); /*FixIndicatorOrderingD(smaValues.ToList(), outBegIdx, outNbElement);*/
            }

            throw new Exception("Could not calculate SMA!");
        }
        public static List <double> Ema(List <double> source, int period)
        {
            // int outBegIdx, outNbElement;
            double[] emaValues = new double[source.Count];
            //List<double?> outValues = new List<double?>();

            var sourceFix = source.ToArray();

            var sma = TA.Ema(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, emaValues);

            if (sma == TA.RetCode.Success)
            {
                return(emaValues.Take(outNbElement).ToList());
            }

            throw new Exception("Could not calculate EMA!");
        }
        public static List <double> Mfi(List <Candle> source, int MfiPeriod)
        {
            double[] mfiValues = new double[source.Count];

            var highs   = source.Select(x => Convert.ToDouble(x.High)).ToArray();
            var lows    = source.Select(x => Convert.ToDouble(x.Low)).ToArray();
            var closes  = source.Select(x => Convert.ToDouble(x.Close)).ToArray();
            var volumes = source.Select(x => Convert.ToDouble(x.Volume)).ToArray();

            var mfi = TA.Mfi(0, source.Count - 1, highs, lows, closes, volumes, MfiPeriod, out int outBegIdx, out int outNbElement, mfiValues);

            if (mfi == TA.RetCode.Success)
            {
                return(mfiValues.Take(outNbElement + 1).Skip(outBegIdx).ToList());
            }

            throw new Exception("Could not calculate MFI!");
        }