public static StochItem Stoch(this IEnumerable <ICandle> candles, int?fastPeriod = null, int?slowKPeriod = null, TicTacTec.TA.Library.Core.MAType?slowKmaType = null, int?slowDPeriod = null, TicTacTec.TA.Library.Core.MAType?slowDmaType = null) { fastPeriod ??= 5; slowKPeriod ??= 3; slowKmaType ??= TicTacTec.TA.Library.Core.MAType.Sma; slowDPeriod ??= 3; slowDmaType ??= TicTacTec.TA.Library.Core.MAType.Sma; IIndicatorOptions options = new StochOptions(fastPeriod.Value, slowDPeriod.Value, slowKmaType.Value, slowDPeriod.Value, slowDmaType.Value); Stoch stosh = new Stoch(); return((StochItem)stosh.Get(candles, options)); }
public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null) { StochOptions config = options != null ? (StochOptions)options.Options : new StochOptions(5, 2, TicTacTec.TA.Library.Core.MAType.Sma, 3, TicTacTec.TA.Library.Core.MAType.Sma); double[] kValues = new double[source.Count()]; double[] dValues = new double[source.Count()]; double[] highs = source.Select(x => Convert.ToDouble(x.High)).ToArray(); double[] lows = source.Select(x => Convert.ToDouble(x.Low)).ToArray(); double[] closes = source.Select(x => Convert.ToDouble(x.Close)).ToArray(); TicTacTec.TA.Library.Core.RetCode stoch = TicTacTec.TA.Library.Core.Stoch(0, source.Count() - 1, highs, lows, closes, config.FastKPeriod, config.SlowKPeriod, config.SlowKmaType, config.SlowDPeriod, config.SlowDmaType, out int outBegIdx, out int outNbElement, kValues, dValues); if (stoch == TicTacTec.TA.Library.Core.RetCode.Success) { return(new StochItem() { D = FixIndicatorOrdering(dValues.ToList(), outBegIdx, outNbElement), K = FixIndicatorOrdering(kValues.ToList(), outBegIdx, outNbElement) }); } throw new Exception("Could not calculate STOCH!"); }