public static MacdItem Macd(this IEnumerable <ICandle> candles, int?fastPeriod = null, int?slowPeriod = null, int?signalPeriod = null) { fastPeriod ??= 12; slowPeriod ??= 26; signalPeriod ??= 9; IIndicatorOptions options = new MacdOptions(fastPeriod.Value, slowPeriod.Value, signalPeriod.Value); Macd macd = new Macd(); return((MacdItem)macd.Get(candles, options)); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { MacdOptions config = options != null ? (MacdOptions)options.Options : new MacdOptions(26, 12, 9); double[] macdValues = new double[source.Count()]; double[] signalValues = new double[source.Count()]; double[] histValues = new double[source.Count()]; double[] closes = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode macd = TicTacTec.TA.Library.Core.Macd(0, source.Count() - 1, closes, config.FastPeriod, config.SlowPeriod, config.SignalPeriod, out int outBegIdx, out int outNbElement, macdValues, signalValues, histValues); if (macd == TicTacTec.TA.Library.Core.RetCode.Success) { return(new MacdItem() { Macd = FixIndicatorOrdering(macdValues.ToList(), outBegIdx, outNbElement), Signal = FixIndicatorOrdering(signalValues.ToList(), outBegIdx, outNbElement), Hist = FixIndicatorOrdering(histValues.ToList(), outBegIdx, outNbElement) }); } throw new Exception("Could not calculate MACD!"); }