private DiverSpan GetDivergence() { var allDivers = new List <DiverSpan>(); foreach (var ind in IndexList) { var indexDiv = ind; var divers = ind.DiverType == IndexDivergencyInfo.DivergenceType.Классические ? Divergency.FindDivergencePointsClassic(candles.Count, ind.PeriodExtremum, ind.MaxPastExtremum, index => candles[index].close, index => indexDiv.lastIndicies[index], ind.WaitOneBar) : Divergency.FindDivergencePointsQuasi(candles.Count, (double)ind.IndexMarginUp, (double)ind.IndexMarginDn, index => candles[index].close, index => indexDiv.lastIndicies[index]); allDivers.AddRange(divers); } // нас интересует знак последнего дивера var diverSpan = allDivers.Count == 0 ? null : allDivers[allDivers.IndexOfMin(d => - d.end)]; if (diverSpan != null && candles.Count - diverSpan.end > ForgetDiverCandles) { diverSpan = null; // дивер устарел } return(diverSpan); }
/// <summary> /// полу-классические диверы: первая точка должна быть экстремумом /// </summary> private List <DiverSpan> FindDivergencePointsClassic() { return(Divergency.FindDivergencePointsClassic(SourceDataCount, PeriodExtremum, MaxPastExtremum, GetSourcePrice, GetIndexPrice, WaitOneBar)); }
private int FindDivPointsClassic(List <CandleData> candles) { var spans = Divergency.FindDivergencePointsClassic(candles.Count, periodExtremum, maxPastExtremum, i => (double)candles[i].close, i => lastIndicies[i], WaitOneBar); return(spans.Sum(s => s.end == candles.Count - (WaitOneBar ? 2 : 1) ? s.sign : 0)); }