예제 #1
0
        public override double Update(double newValue)
        {
            double oldMACD   = Fast.Value - Slow.Value;
            double oldSignal = Signal.Value;

            Fast.Update(newValue);
            Slow.Update(newValue);

            double newMACD = Fast.Value - Slow.Value;

            Signal.Update(newMACD);
            double newSignal = Signal.Value;

            MACDCrossedSignal   = (Math.Sign(oldSignal - oldMACD) != Math.Sign(newSignal - newMACD));
            MACDCrossedZero     = (Math.Sign(oldMACD) != Math.Sign(newMACD));
            MACDStockDivergence = Math.Sign(maxValue - newValue) != Math.Sign(maxMACDValue - newMACD);

            if (newValue > maxValue)
            {
                maxValue = newValue;
            }

            if (newMACD > maxMACDValue)
            {
                maxMACDValue = newMACD;
            }

            MACDValue   = newMACD;
            SignalValue = newSignal;

            return(Value);
        }
        /// <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(IndicatorDataPoint input)
        {
            Fast.Update(input);
            Slow.Update(input);

            var macd = Fast - Slow;

            Signal.Update(input.Time, macd);
            Histogram.Update(input.Time, macd - Signal);
            return(macd);
        }
        /// <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)
        {
            Fast.Update(time, input);
            Slow.Update(time, input);

            var macd = Fast - Slow;

            Signal.Update(time, macd);
            Histogram.Update(time, macd - Signal);
            return(macd);
        }
        /// <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(IndicatorDataPoint input)
        {
            Fast.Update(input);
            Slow.Update(input);

            var macd = Fast - Slow;

            if (Fast.IsReady && Slow.IsReady)
            {
                Signal.Update(input.Time, macd);
            }

            return(macd);
        }
예제 #5
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(IndicatorDataPoint input)
        {
            var fastReady = Fast.Update(input);
            var slowReady = Slow.Update(input);

            var macd = Fast.Current.Value - Slow.Current.Value;

            if (fastReady && slowReady)
            {
                if (Signal.Update(input.Time, macd))
                {
                    Histogram.Update(input.Time, macd - Signal.Current.Value);
                }
            }

            return(macd);
        }