コード例 #1
0
        /// <summary>
        /// Adds an index to the moving average.
        /// </summary>
        /// <param name="value">The index value.</param>
        public void AddIndex(decimal value)
        {
            if (_previous != decimal.MinValue)
            {
                if (value >= _previous)
                {
                    _gainAverage.AddIndex(value - _previous);
                    _lossAverage.AddIndex(0);
                }
                else
                {
                    _gainAverage.AddIndex(0);
                    _lossAverage.AddIndex(_previous - value);
                }
            }

            _previous = value;

            if (_lossAverage.GetValue() == 0)
            {
                _strength = 100;
                return;
            }

            var relativeStrength = _gainAverage.GetValue() / _lossAverage.GetValue();

            _strength = 100 - (100 / (1 + relativeStrength));
        }
コード例 #2
0
        /// <summary>
        /// Adds an index to the moving average.
        /// </summary>
        /// <param name="value">The index value.</param>
        public void AddIndex(decimal value)
        {
            _slowAverage.AddIndex(value);
            _fastAverage.AddIndex(value);

            if (_slowAverage.IsReady() && _fastAverage.IsReady())
            {
                _signAverage.AddIndex(_fastAverage.GetValue() - _slowAverage.GetValue());
            }
        }