Example #1
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IBaseDataBar input)
        {
            _trueRange.Update(input);
            _directionalMovementPlus.Update(input);
            _directionalMovementMinus.Update(input);
            _smoothedTrueRange.Update(Current);
            _smoothedDirectionalMovementPlus.Update(Current);
            _smoothedDirectionalMovementMinus.Update(Current);
            _previousInput = input;

            PositiveDirectionalIndex.Update(Current);
            NegativeDirectionalIndex.Update(Current);

            var diff = Math.Abs(PositiveDirectionalIndex.Current.Value - NegativeDirectionalIndex.Current.Value);
            var sum  = PositiveDirectionalIndex.Current.Value + NegativeDirectionalIndex.Current.Value;

            if (sum == 0)
            {
                return(50m);
            }

            _averageDirectionalIndex.Update(input.EndTime, 100m * diff / sum);

            return(_averageDirectionalIndex.Current.Value);
        }
        /// <summary>
        ///      Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="time"></param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            _trueRange.Update(time, input);
            _directionalMovementPlus.Update(time, input);
            _directionalMovementMinus.Update(time, input);
            _smoothedTrueRange.Update(time, Current);
            _smoothedDirectionalMovementPlus.Update(time, Current);
            _smoothedDirectionalMovementMinus.Update(time, Current);
            _previousInput = input.Clone();

            PositiveDirectionalIndex.Update(time, Current);
            NegativeDirectionalIndex.Update(time, Current);

            var diff = Math.Abs(PositiveDirectionalIndex.Current.Value - NegativeDirectionalIndex);
            var sum  = PositiveDirectionalIndex + NegativeDirectionalIndex;

            if (sum == 0)
            {
                return((DoubleArray)50d);
            }

            _averageDirectionalIndex.Update(time, 100d * diff / sum);

            return(_averageDirectionalIndex);
        }
Example #3
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IBaseDataBar input)
        {
            TrueRange.Update(input);
            DirectionalMovementPlus.Update(input);
            DirectionalMovementMinus.Update(input);
            SmoothedTrueRange.Update(Current);
            SmoothedDirectionalMovementMinus.Update(Current);
            SmoothedDirectionalMovementPlus.Update(Current);
            if (_previousInput != null)
            {
                PositiveDirectionalIndex.Update(Current);
                NegativeDirectionalIndex.Update(Current);
            }
            var diff  = Math.Abs(PositiveDirectionalIndex - NegativeDirectionalIndex);
            var sum   = PositiveDirectionalIndex + NegativeDirectionalIndex;
            var value = sum == 0 ? 50 : ((_period - 1) * Current.Value + 100 * diff / sum) / _period;

            _previousInput = input;
            return(value);
        }