public static TrueRange Create()
        {
            double Function(CandleTimeSeries series, DateTime date)
            {
                Candle currentCandle  = series[date];
                int    index          = series.GetIndex(currentCandle);
                Candle previousCandle = series[index - 1];

                double trueRange = Utils.Max(
                    currentCandle.Max - currentCandle.Min,
                    currentCandle.Max - previousCandle.Close,
                    currentCandle.Min - previousCandle.Close);

                return(trueRange);
            }

            TrueRange ind = new TrueRange(Function);

            return(ind);
        }
        public static AverageTrueRange Create(int smoothingPeriods)
        {
            TrueRange tr = TrueRange.Create();

            double Function(CandleTimeSeries series, DateTime date)
            {
                Candle candle = series[date];
                int    index  = series.GetIndex(candle);

                Candle[] candles = index.GetIntegersTo(Math.Max(1, index - smoothingPeriods))
                                   .Select(idx => series[idx])
                                   .ToArray();
                double ema = candles
                             .WeightedAverage((cdl, idx) => tr[series, cdl.Start],
                                              (cdl, idx) => candles.Length - idx);

                return(ema);
            }

            AverageTrueRange ind = new AverageTrueRange(Function);

            return(ind);
        }