public static DirectionalMovementMinus 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(dm > um && dm > 0 ? dm : 0); } DirectionalMovementMinus result = new DirectionalMovementMinus(Function); return(result); }
public static AverageDirectionalMovementMinus Create( int periods ) { DirectionalMovementMinus dmMinus = DirectionalMovementMinus.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) => dmMinus[series, cdl.Start], (cdl, idx) => candles.Length - idx); return(ema); } AverageDirectionalMovementMinus plus = new AverageDirectionalMovementMinus(Function); return(plus); }