Example #1
0
        /// <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);

            if (Samples == 1)
            {
                _previousInput = input.Clone();
                return(50.0d);
            }

            var buyingPressure = new DoubleArrayScalar(input[CloseIdx] - Math.Min(input[LowIdx], _previousInput.Close));

            _sumBuyingPressure1.Update(time, buyingPressure);
            _sumBuyingPressure2.Update(time, buyingPressure);
            _sumBuyingPressure3.Update(time, buyingPressure);

            _sumTrueRange1.Update(time, _trueRange.Current);
            _sumTrueRange2.Update(time, _trueRange.Current);
            _sumTrueRange3.Update(time, _trueRange.Current);

            _previousInput = input;

            if (!IsReady)
            {
                return(50.0d);
            }

            var average1 = _sumBuyingPressure1 / _sumTrueRange1;
            var average2 = _sumBuyingPressure2 / _sumTrueRange2;
            var average3 = _sumBuyingPressure3 / _sumTrueRange3;

            return(100.0d * (4 * average1 + 2 * average2 + average3) / 7);
        }
Example #2
0
        /// <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)
        {
            // compute the true range and then send it to our smoother
            TrueRange.Update(time, input);
            _smoother.Update(time, TrueRange);

            return(_smoother.Current.Value);
        }
Example #3
0
        /// <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)
        {
            _tr.Update(time, input);

            if (!IsReady)
            {
                _atr.Update(time, input);
                return(input[CloseIdx] != 0 ? _atr / input[CloseIdx] * 100 : 0d);
            }

            if (Samples == _period + 1)
            {
                // first output value is SMA of TrueRange
                _atr.Update(time, input);
                _lastAtrValue = _atr;
            }
            else
            {
                // next TrueRange values are smoothed using Wilder's approach
                _lastAtrValue = (_lastAtrValue * (_period - 1) + _tr) / _period;
            }

            return(input[CloseIdx] != 0 ? _lastAtrValue / input[CloseIdx] * 100 : 0d);
        }