/// <summary> /// Calculate a single value of %D line /// </summary> /// <param name="data">List of prices</param> /// <param name="period">Period of calculation</param> /// <param name="k_period">Period of calculation for %K</param> public static double?D_Single(double[] data, int period, int k_period = 3) { if (data.Length < period) { return(0); } var k_list = new List <double>(); for (int i = 0; i < period; i++) { var selected_data = data.Skip(data.Length - (period + i)).Take(period).ToArray(); k_list.Add(K_Single(selected_data, period)); } var ma = new MA(); return(ma.SmaSingle(k_list.ToArray(), k_period)); }
/// <summary> /// Calculate a single MACD /// </summary> /// <param name="data">List of prices</param> /// <param name="fast">Period of fast ema calculation</param> /// <param name="slow">Period of slow ema calculation</param> public static double?MacdSingle(double[] data, int fast = 12, int slow = 26) { var ma = new MA(); return(ma.EmaSingle(data, fast) - ma.EmaSingle(data, slow)); }