예제 #1
0
        public SimpleMovingAverageOscillator(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, int periodCount1, int periodCount2) : base(inputs, inputMapper)
        {
            _sma1 = new SimpleMovingAverageByTuple(inputs.Select(inputMapper), periodCount1);
            _sma2 = new SimpleMovingAverageByTuple(inputs.Select(inputMapper), periodCount2);

            PeriodCount1 = periodCount1;
            PeriodCount2 = periodCount2;
        }
예제 #2
0
        protected override decimal?ComputeByIndexImpl(IReadOnlyList <decimal?> mappedInputs, int index)
        {
            _v = _v ?? Enumerable.Range(0, mappedInputs.Count).Select(i =>
            {
                var sd         = new StandardDeviationByTuple(mappedInputs, SdPeriod);
                var smoothedSd = new SimpleMovingAverageByTuple(sd.Compute(), SmoothedSdPeriod);
                return(sd[i] / smoothedSd[i]);
            }).ToList();

            var t         = _v[index].GetValueOrDefault() != 0 ? (int)Math.Floor(RsiPeriod / _v[index].Value) : default(int?);
            var tAdjusted = t.HasValue ? Math.Max(Math.Min(t.Value, UpLimit), LowLimit) : default(int?);

            return(tAdjusted.HasValue ? new RelativeStrengthIndexByTuple(mappedInputs, tAdjusted.Value)[index] : default(decimal?));
        }