예제 #1
0
 /// <summary>
 ///      Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     _previous = null;
     _smoother.Reset();
     TrueRange.Reset();
     base.Reset();
 }
예제 #2
0
 /// <summary>
 ///      Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     FastStoch.Reset();
     StochK.Reset();
     StochD.Reset();
     _maximum.Reset();
     _minimum.Reset();
     _sumFastK.Reset();
     _sumSlowK.Reset();
     base.Reset();
 }
 /// <summary>
 ///      Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     _previousInput = null;
     _trueRange.Reset();
     _directionalMovementPlus.Reset();
     _directionalMovementMinus.Reset();
     _smoothedTrueRange.Reset();
     _smoothedDirectionalMovementPlus.Reset();
     _smoothedDirectionalMovementMinus.Reset();
     _averageDirectionalIndex.Reset();
     PositiveDirectionalIndex.Reset();
     NegativeDirectionalIndex.Reset();
     base.Reset();
 }
        /// <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);
        }