示例#1
0
        /// <summary>
        /// Обработать входное значение.
        /// </summary>
        /// <param name="input">Входное значение.</param>
        /// <returns>Результирующее значение.</returns>
        protected override IIndicatorValue OnProcess(IIndicatorValue input)
        {
            decimal?result = null;

            var candle = input.GetValue <Candle>();

            // задержка в 1 период
            _isFormed = _averageTrueRange.IsFormed && _movingAverage.IsFormed;

            _averageTrueRange.Process(input);

            if (_lastCandle != null)
            {
                var trValue = _averageTrueRange.GetCurrentValue();

                // не вносить в тернарный оператор!
                var maValue = _movingAverage.Process(new DecimalIndicatorValue(this, GetValue(candle, _lastCandle))
                {
                    IsFinal = input.IsFinal
                });

                if (!maValue.IsEmpty)
                {
                    result = (trValue != 0m) ? (100m * maValue.GetValue <decimal>() / trValue) : 0m;
                }
            }

            if (input.IsFinal)
            {
                _lastCandle = candle;
            }

            return(result == null ? new DecimalIndicatorValue(this) : new DecimalIndicatorValue(this, result.Value));
        }
示例#2
0
        /// <summary>
        /// To handle the input value.
        /// </summary>
        /// <param name="input">The input value.</param>
        /// <returns>The resulting value.</returns>
        protected override IIndicatorValue OnProcess(IIndicatorValue input)
        {
            decimal?result = null;

            var candle = input.GetValue <Candle>();

            // 1 period delay
            _isFormed = _averageTrueRange.IsFormed && _movingAverage.IsFormed;

            _averageTrueRange.Process(input);

            if (_lastCandle != null)
            {
                var trValue = _averageTrueRange.GetCurrentValue();

                var maValue = _movingAverage.Process(new DecimalIndicatorValue(this, GetValue(candle, _lastCandle))
                {
                    IsFinal = input.IsFinal
                });

                if (!maValue.IsEmpty)
                {
                    result = trValue != 0m ? 100m * maValue.GetValue <decimal>() / trValue : 0m;
                }
            }

            if (input.IsFinal)
            {
                _lastCandle = candle;
            }

            return(result == null ? new DecimalIndicatorValue(this) : new DecimalIndicatorValue(this, result.Value));
        }