Exemplo n.º 1
0
        /// <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 decimal ComputeStochK(int period, int constantK, TradeBar input)
        {
            var stochK = _maximum.Samples >= (period + constantK - 1) ? _sumFastK / constantK : new decimal(0.0);

            _sumSlowK.Update(input.Time, stochK);
            return(stochK * 100);
        }
Exemplo n.º 2
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(TradeBar input)
        {
            // compute the true range and then send it to our smoother
            TrueRange.Update(input);
            _smoother.Update(input.Time, TrueRange);

            return(_smoother.Current.Value);
        }
Exemplo n.º 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>
 protected override decimal ComputeNextValue(TradeBar input)
 {
     _maximum.Update(input.Time, input.High);
     _mininum.Update(input.Time, input.Low);
     FastStoch.Update(input);
     StochK.Update(input);
     StochD.Update(input);
     return(FastStoch);
 }
Exemplo n.º 4
0
        /// <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 decimal ComputeFastStoch(int period, TradeBar input)
        {
            var     denominator = (_maximum - _mininum);
            var     numerator   = (input.Close - _mininum);
            decimal fastStoch;

            if (denominator == 0m)
            {
                // if there's no range, just return constant zero
                fastStoch = 0m;
            }
            else
            {
                fastStoch = _maximum.Samples >= period ? numerator / denominator : new decimal(0.0);
            }
            _sumFastK.Update(input.Time, fastStoch);
            return(fastStoch * 100);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Updates the state of this indicator with the given value and returns true
 /// if this indicator is ready, false otherwise
 /// </summary>
 /// <param name="indicator">The indicator to be updated</param>
 /// <param name="time">The time associated with the value</param>
 /// <param name="value">The value to use to update this indicator</param>
 /// <returns>True if this indicator is ready, false otherwise</returns>
 public static bool Update(this IndicatorBase <IndicatorDataPoint> indicator, DateTime time, decimal value)
 {
     return(indicator.Update(new IndicatorDataPoint(time, value)));
 }