예제 #1
0
        public static BbandItem Bbands(this IEnumerable <ICandle> candles, int?period = null, double?devUp = null, double?devDown = null, TicTacTec.TA.Library.Core.MAType?type = null)
        {
            period ??= 5;
            devUp ??= 2;
            devDown ??= 2;
            type ??= TicTacTec.TA.Library.Core.MAType.Sma;

            IIndicatorOptions options = new BbandsOptions(period.Value, devUp.Value, devDown.Value, type.Value);
            Bbands            bbands  = new Bbands();

            return((BbandItem)bbands.Get(candles, options));
        }
예제 #2
0
        public override dynamic Get(IEnumerable <ICandle> source, IIndicatorOptions options = null)
        {
            BbandsOptions config = options != null ? (BbandsOptions)options.Options : new BbandsOptions(5, 2, 2, TicTacTec.TA.Library.Core.MAType.Sma);

            double[] upperValues  = new double[source.Count()];
            double[] middleValues = new double[source.Count()];
            double[] lowerValues  = new double[source.Count()];
            double[] closes       = source.Select(x => Convert.ToDouble(x.Close)).ToArray();

            var bbands = TicTacTec.TA.Library.Core.Bbands(0, source.Count() - 1, closes, config.Period, config.DevUp, config.DevDown, config.Type, out int outBegIdx, out int outNbElement, upperValues, middleValues, lowerValues);

            if (bbands == TicTacTec.TA.Library.Core.RetCode.Success)
            {
                return(new BbandItem()
                {
                    UpperBand = FixIndicatorOrdering(upperValues.ToList(), outBegIdx, outNbElement),
                    MiddleBand = FixIndicatorOrdering(middleValues.ToList(), outBegIdx, outNbElement),
                    LowerBand = FixIndicatorOrdering(lowerValues.ToList(), outBegIdx, outNbElement)
                });
            }

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