Example #1
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="window"></param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>
        /// A new value for this indicator
        /// </returns>
        protected override decimal ComputeNextValue(IReadOnlyWindow <IndicatorDataPoint> window, IndicatorDataPoint input)
        {
            if (window.Count >= 3)
            {
                _multipliedDiffWindow.Add((window[0] - window[1]) * (window[1] - window[2]));
            }

            // Estimate the indicator if less than 50% of observation are zero. Avoid division by
            // zero and estimations with few real observations in case of forward filled data.
            if (IsReady && _multipliedDiffWindow.Count(obs => obs == 0) < 0.5 * _multipliedDiffWindow.Count)
            {
                var mc  = _multipliedDiffWindow.Count(obs => obs > 0);
                var mRc = _multipliedDiffWindow.Count(obs => obs < 0);
                return(100m * mc / (mc + mRc));
            }
            return(50m);
        }
Example #2
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="window"></param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>
        /// A new value for this indicator
        /// </returns>
        protected override decimal ComputeNextValue(IReadOnlyWindow <IndicatorDataPoint> window, IndicatorDataPoint input)
        {
            int     Mc        = 0;
            int     MRc       = 0;
            decimal momersion = 50m;

            if (window.Count >= 3)
            {
                _multipliedDiffWindow.Add((window[0] - window[1]) * (window[1] - window[2]));
            }

            // Estimate the indicator if less than 50% of observation are zero. Avoid division by
            // zero and estimations with few real observations in case of forward filled data.
            if (this.IsReady &&
                _multipliedDiffWindow.Count(obs => obs == 0) < 0.5 * _multipliedDiffWindow.Count)
            {
                Mc        = _multipliedDiffWindow.Count(obs => obs > 0);
                MRc       = _multipliedDiffWindow.Count(obs => obs < 0);
                momersion = 100m * Mc / (Mc + MRc);
            }
            return(momersion);
        }