/// <summary> /// Initializes a new instance of the MeanAbsoluteDeviation class with the specified period. /// /// Evaluates the mean absolute deviation of samples in the look-back period. /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The sample size of the mean absolute deviation</param> public MeanAbsoluteDeviation(string name, int period) : base(name, period) { Mean = new SimpleMovingAverage($"{name}_Mean", period); }
/// <summary> /// Initializes a new instance of the <see cref="AverageDirectionalIndex"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="period">The period.</param> public AverageDirectionalIndex(string name, int period) : base(name) { _period = period; _trueRange = new FunctionalIndicator(name + "_TrueRange", ComputeTrueRange, isReady => _previousInput != null ); _directionalMovementPlus = new FunctionalIndicator(name + "_PositiveDirectionalMovement", ComputePositiveDirectionalMovement, isReady => _previousInput != null ); _directionalMovementMinus = new FunctionalIndicator(name + "_NegativeDirectionalMovement", ComputeNegativeDirectionalMovement, isReady => _previousInput != null ); PositiveDirectionalIndex = new FunctionalIndicator(name + "_PositiveDirectionalIndex", (time, input) => { // Computes the Plus Directional Indicator(+DI period). if (_smoothedTrueRange != 0 && _smoothedDirectionalMovementPlus.IsReady) { return((DoubleArray)100d * _smoothedDirectionalMovementPlus / _smoothedTrueRange); } return(Constants.Zero); }, positiveDirectionalIndex => _smoothedDirectionalMovementPlus.IsReady, () => { _directionalMovementPlus.Reset(); _trueRange.Reset(); } ); NegativeDirectionalIndex = new FunctionalIndicator(name + "_NegativeDirectionalIndex", (time, input) => { // Computes the Minus Directional Indicator(-DI period). if (_smoothedTrueRange != 0 && _smoothedDirectionalMovementMinus.IsReady) { return(100d * _smoothedDirectionalMovementMinus / _smoothedTrueRange); } return(Constants.Zero); }, negativeDirectionalIndex => _smoothedDirectionalMovementMinus.IsReady, () => { _directionalMovementMinus.Reset(); _trueRange.Reset(); } ); _smoothedTrueRange = new FunctionalIndicator(name + "_SmoothedTrueRange", (time, input) => { // Computes the Smoothed True Range value. var value = Samples > _period + 1 ? _smoothedTrueRange / _period : Constants.Zero; return(_smoothedTrueRange + _trueRange - value); }, isReady => Samples > period ); _smoothedDirectionalMovementPlus = new FunctionalIndicator(name + "_SmoothedDirectionalMovementPlus", (time, input) => { // Computes the Smoothed Directional Movement Plus value. var value = Samples > _period + 1 ? _smoothedDirectionalMovementPlus / _period : Constants.Zero; return(_smoothedDirectionalMovementPlus + _directionalMovementPlus - value); }, isReady => Samples > period ); _smoothedDirectionalMovementMinus = new FunctionalIndicator(name + "_SmoothedDirectionalMovementMinus", (time, input) => { // Computes the Smoothed Directional Movement Minus value. var value = Samples > _period + 1 ? _smoothedDirectionalMovementMinus / _period : Constants.Zero; return(_smoothedDirectionalMovementMinus + _directionalMovementMinus - value); }, isReady => Samples > period ); _averageDirectionalIndex = new WilderMovingAverage(period); }