protected override IndicatorResult ComputeByIndexImpl(int index) { if (index < PeriodCount - 1) { return(new IndicatorResult(Equity[index].DateTime, null)); } var values = Equity.Skip(index - PeriodCount + 1).Take(PeriodCount).Select(c => c.Close); decimal avg = values.Average(); double diffSum = values.Select(v => Convert.ToDouble((v - avg) * (v - avg))).Sum(); decimal sd = Convert.ToDecimal(Math.Sqrt(diffSum / (values.Count() - 1))); return(new IndicatorResult(Equity[index].DateTime, sd)); }
protected override IndicatorResult ComputeByIndexImpl(int index) { if (index < PeriodCount - 1) { return(new IndicatorResult(Equity[index].DateTime, null, null)); } var highestCloseIndex = index - PeriodCount + 1 + Equity .Skip(index - PeriodCount + 1) .Take(PeriodCount) .ToList() .FindLastIndexOrDefault(c => c.High == _highestHigh.ComputeByIndex(index).HighestHigh).Value; var lowestCloseIndex = index - PeriodCount + 1 + Equity .Skip(index - PeriodCount + 1) .Take(PeriodCount) .ToList() .FindLastIndexOrDefault(c => c.Low == _lowestLow.ComputeByIndex(index).LowestLow).Value; var up = 100.0m * (PeriodCount - (index - highestCloseIndex)) / PeriodCount; var down = 100.0m * (PeriodCount - (index - lowestCloseIndex)) / PeriodCount; return(new IndicatorResult(Equity[index].DateTime, up, down)); }
protected override IndicatorResult ComputeByIndexImpl(int index) { decimal?highestHigh = index >= PeriodCount - 1 ? Equity.Skip(index - PeriodCount + 1).Take(PeriodCount).Max(c => c.High) : (decimal?)null; return(new IndicatorResult(Equity[index].DateTime, highestHigh)); }
protected override PatternResult <Match?> ComputeByIndexImpl(int index) { bool isHighest = Equity.Skip(Equity.Count - PeriodCount).Max(c => c.Close) == Equity[index].Close; return(new PatternResult <Match?>(Equity[index].DateTime, Decision.IsMatch(isHighest))); }
protected override IndicatorResult ComputeByIndexImpl(int index) { decimal?lowestLow = index >= PeriodCount - 1 ? Equity.Skip(index - PeriodCount + 1).Take(PeriodCount).Min(c => c.Low) : (decimal?)null; return(new IndicatorResult(Equity[index].DateTime, lowestLow)); }
protected override IndicatorResult ComputeByIndexImpl(int index) { decimal?sma = index >= PeriodCount - 1 ? Equity.Skip(index - PeriodCount + 1).Take(PeriodCount).Average(c => c.Close) : (decimal?)null; return(new IndicatorResult(Equity[index].DateTime, sma)); }