public static DirectionalMovementPlus Create()
        {
            double Function(CandleTimeSeries series, DateTime instant)
            {
                Candle currentCandle  = series[instant];
                int    index          = series.GetIndex(currentCandle);
                Candle previousCandle = series[index - 1];
                double um             = Utils.Max(currentCandle.Max - previousCandle.Max, 0);
                double dm             = Utils.Max(previousCandle.Min - currentCandle.Min, 0);

                return(um > dm &&
                       um > 0
                    ? um
                    : 0);
            }

            DirectionalMovementPlus result = new DirectionalMovementPlus(Function);

            return(result);
        }
        public static AverageDirectionalMovementPlus Create(
            int periods)
        {
            DirectionalMovementPlus dmPlus = DirectionalMovementPlus.Create( );

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

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

                return(ema);
            }

            AverageDirectionalMovementPlus plus = new AverageDirectionalMovementPlus(Function);

            return(plus);
        }