Beispiel #1
0
        public MACDIndicator(DateTime time, double closePrice, IMACD preMACD = null)
        {
            // 快速移动平均值周期 默认12
            SlowEMACycle = SHORT;

            // 快速移动平均值  EMA12 = 前一日EMA12 X 11/13 + 今日收盘 X 2/13
            SlowEMA = (preMACD == null ? closePrice : (2 * closePrice + (SHORT - 1) * preMACD.SlowEMA) / (SHORT + 1));

            // 慢速移动平均值 默认26
            FastEMACycle = LONG;

            // 慢速移动平均值  EMA26 = 前一日EMA26 X 25/27 + 今日收盘 X 2/27
            FastEMA = (preMACD == null ? closePrice : (2 * closePrice + (LONG - 1) * preMACD.FastEMA) / (LONG + 1));

            // 差离值   DIF = EMA12 - EMA26
            DIF = SlowEMA - FastEMA;

            // 离差平均值   DEA = (前一日DEA X 8/10 + 今日DIF X 2/10)
            DEA = (preMACD == null ? DIF : (2 * DIF + (M - 1) * preMACD.DEA) / (M + 1));

            // MACD 指数平滑移动平均线 (DIF-DEA)*2
            MACD = 2.0 * (DIF - DEA);

            Time = time;
        }
Beispiel #2
0
        private static IMACD MACD(this IEnumerable<IStockKLine> self, int index, IMACD preMACD = null)
        {
            if (self == null || self.Count() <= index)
                return null;

            var lstStockKLine = self.ToList();
            if (index == 0)
            {
                return new MACDIndicator(lstStockKLine[index].Time, lstStockKLine[index].Close);
            }
            else
            {
                return new MACDIndicator(lstStockKLine[index].Time, lstStockKLine[index].Close, preMACD);
            }
        }