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; }
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); var currentSmoothedSd = smoothedSd[i]; return(currentSmoothedSd == 0 ? default : sd[i] / currentSmoothedSd); }).ToList(); var currentV = _v[index]; var t = currentV.GetValueOrDefault() != 0 ? (int?)Math.Floor(RsiPeriod / currentV.Value) : default; var tAdjusted = t.HasValue ? (int?)Math.Max(Math.Min(t.Value, UpLimit), LowLimit) : default; return(tAdjusted.HasValue ? new RelativeStrengthIndexByTuple(mappedInputs, tAdjusted.Value)[index] : default);