public static DirectionalIndicatorMinus Create(int periods) { AverageDirectionalMovementMinus admMinus = AverageDirectionalMovementMinus.Create(periods); AverageTrueRange atr = AverageTrueRange.Create(periods); double Function(CandleTimeSeries series, DateTime instant) { return(admMinus[series, instant].DivideBy(atr[series, instant])); } DirectionalIndicatorMinus result = new DirectionalIndicatorMinus(Function); return(result); }
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); }