Exemple #1
0
        public RelativeStrength(Equity equity, int periodCount) : base(equity, periodCount)
        {
            _closePriceChangeIndicator = new ClosePriceChange(equity);

            Func <int, decimal> u = i => Math.Max(_closePriceChangeIndicator.ComputeByIndex(i).Change.Value, 0);
            Func <int, decimal> l = i => Math.Abs(Math.Min(_closePriceChangeIndicator.ComputeByIndex(i).Change.Value, 0));

            _uEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => u(j)) : (decimal?)null,
                i => u(i),
                i => 1.0m / periodCount);

            _dEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => l(j)) : (decimal?)null,
                i => l(i),
                i => 1.0m / periodCount);
        }
Exemple #2
0
        public RelativeStrength(IList <decimal> closes, int periodCount) : base(closes)
        {
            _closePriceChange = new ClosePriceChange(closes);

            Func <int, decimal?> u = i => i > 0 ? Math.Max(_closePriceChange[i].Value, 0) : (decimal?)null;
            Func <int, decimal?> l = i => i > 0 ? Math.Abs(Math.Min(_closePriceChange[i].Value, 0)) : (decimal?)null;

            _uEma = new GenericExponentialMovingAverage <decimal>(
                closes,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => u(j)) : null,
                i => u(i),
                i => 1.0m / periodCount);

            _dEma = new GenericExponentialMovingAverage <decimal>(
                closes,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => l(j)) : null,
                i => l(i),
                i => 1.0m / periodCount);

            PeriodCount = periodCount;
        }