コード例 #1
0
ファイル: Stochastics.cs プロジェクト: useric/FinanceSharp
        /// <summary>
        ///      Computes the Slow Stochastic %K.
        /// </summary>
        /// <param name="period">The period.</param>
        /// <param name="constantK">The constant k.</param>
        /// <param name="input">The input.</param>
        /// <returns>The Slow Stochastics %K value.</returns>
        private double ComputeStochK(int period, int constantK, long time, DoubleArray input)
        {
            var stochK = _maximum.Samples >= (period + constantK - 1) ? _sumFastK / constantK : Constants.Zero;

            _sumSlowK.Update(time, stochK);
            return(stochK * 100);
        }
コード例 #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)
        {
            _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);
        }
コード例 #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)
        {
            // compute the true range and then send it to our smoother
            TrueRange.Update(time, input);
            _smoother.Update(time, TrueRange);

            return(_smoother.Current.Value);
        }
コード例 #4
0
ファイル: Stochastics.cs プロジェクト: useric/FinanceSharp
        /// <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>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            _maximum.Update(time, input[HighIdx]);
            _minimum.Update(time, input[LowIdx]);
            FastStoch.Update(time, input);
            StochK.Update(time, input);
            StochD.Update(time, input);

            return(FastStoch.Current);
        }
コード例 #5
0
ファイル: Stochastics.cs プロジェクト: useric/FinanceSharp
        /// <summary>
        ///      Computes the Fast Stochastic %K.
        /// </summary>
        /// <param name="period">The period.</param>
        /// <param name="input">The input.</param>
        /// <returns>The Fast Stochastics %K value.</returns>
        private double ComputeFastStoch(int period, long time, DoubleArray input)
        {
            var denominator = _maximum - _minimum;

            // if there's no range, just return constant zero
            if (denominator == Constants.Zero)
            {
                return(Constants.Zero);
            }

            var numerator = input[CloseIdx] - _minimum;
            var fastStoch = _maximum.Samples >= period ? numerator / denominator : Constants.Zero;

            _sumFastK.Update(time, fastStoch);
            return(fastStoch * 100);
        }