private void GenerateDetails() { var startDate = DateTime.MinValue; var endDate = DateTime.MaxValue; foreach (var dailyCandle in DailyCandles.Where(dailyCandle => MinuteData.ContainsKey(dailyCandle.Date.Date))) { startDate = dailyCandle.Date; break; } for (var i = DailyCandles.Count - 1; i > 0; i--) { if (MinuteData.ContainsKey(DailyCandles[i].Date.Date)) { endDate = DailyCandles[i].Date; break; } } var high = double.MinValue; var low = double.MaxValue; var date = startDate; var highTime = DateTime.MinValue; var lowTime = DateTime.MinValue; while (date <= endDate) { if (MinuteData.TryGetValue(date.Date, out var minuteCandles)) { foreach (var candle in minuteCandles.Where(candle => candle.IsCash)) { if (candle.AskHigh > high) { high = candle.AskHigh; highTime = candle.DateTime; } if (candle.BidLow < low) { low = candle.BidLow; lowTime = candle.DateTime; } } } date = date.AddDays(1); } var openTime = new TimeSpan(14, 30, 00); var closeTime = new TimeSpan(21, 00, 00); if (IsUkData) { openTime = new TimeSpan(8, 00, 00); closeTime = new TimeSpan(16, 30, 00); } DataDetails = new DataDetails(startDate, endDate, high, highTime, low, lowTime, _averageGapSize, openTime, closeTime); }
private void CalculateGapFibLevelPreHitAdverseExcursions() // todo rename this { var retraces = (FibonacciLevel[])Enum.GetValues(typeof(FibonacciLevel)); for (var i = 0; i < 19; i++) { var hitCount = 0; double preHitMaxTotal = 0; double postHitMaxFavourableTotal = 0; double postHitMaxAdverseTotal = 0; double highestPreHitMax = 0; double highestPostHitMaxFavourable = 0; double highestPostHitMaxAdverse = 0; var highestPreHitMaxDate = DateTime.MinValue; var highestPostHitMaxFavourableDate = DateTime.MinValue; var highestPostHitMaxAdverseDate = DateTime.MinValue; foreach (var dailyCandle in DailyCandles) { var level = i < 10 ? dailyCandle.Open - dailyCandle.Gap.GapPoints * ((double)retraces[i] / 1000) : dailyCandle.Open + dailyCandle.Gap.GapPoints * ((double)retraces[i] / 1000 - 1); if (MinuteData.TryGetValue(dailyCandle.Date.Date, out var minuteCandles)) { var excursions = CompareMinuteData(minuteCandles, dailyCandle, level, false); excursions.IfExistsThen(x => { var(preHitMax, postHitMaxFavourable, postHitMaxAdverse) = x; if (preHitMax > highestPreHitMax) { highestPreHitMax = preHitMax; highestPreHitMaxDate = dailyCandle.Date; } if (postHitMaxFavourable > highestPostHitMaxFavourable) { highestPostHitMaxFavourable = postHitMaxFavourable; highestPostHitMaxFavourableDate = dailyCandle.Date; } if (postHitMaxAdverse > highestPostHitMaxAdverse) { highestPostHitMaxAdverse = postHitMaxAdverse; highestPostHitMaxAdverseDate = dailyCandle.Date; } hitCount++; preHitMaxTotal += preHitMax; postHitMaxFavourableTotal += postHitMaxFavourable; postHitMaxAdverseTotal += postHitMaxAdverse; }); } } if (GapFibRetraceLevels.TryGetValue(retraces[i], out var retraceLevel)) // todo refactor this { retraceLevel.AveragePreHitAdverseExcursion = preHitMaxTotal / hitCount; retraceLevel.HighestPreHitAdverseExcursion = highestPreHitMax; retraceLevel.DateOfHighestPreHitAdverseExcursion = highestPreHitMaxDate; retraceLevel.AveragePostHitFavourableExcursion = postHitMaxFavourableTotal / hitCount; retraceLevel.HighestPostHitFavourableExcursion = highestPostHitMaxFavourable; retraceLevel.DateOfHighestPostHitFavourableExcursion = highestPostHitMaxFavourableDate; retraceLevel.AveragePostHitAdverseExcursion = postHitMaxAdverseTotal / hitCount; retraceLevel.HighestPostHitAdverseExcursion = highestPostHitMaxAdverse; retraceLevel.DateOfHighestPostHitAdverseExcursion = highestPostHitMaxAdverseDate; } if (GapFibExtensionLevels.TryGetValue(retraces[i], out var extensionLevel)) { extensionLevel.AveragePreHitAdverseExcursion = preHitMaxTotal / hitCount; extensionLevel.HighestPreHitAdverseExcursion = highestPreHitMax; extensionLevel.DateOfHighestPreHitAdverseExcursion = highestPreHitMaxDate; extensionLevel.AveragePostHitFavourableExcursion = postHitMaxFavourableTotal / hitCount; extensionLevel.HighestPostHitFavourableExcursion = highestPostHitMaxFavourable; extensionLevel.DateOfHighestPostHitFavourableExcursion = highestPostHitMaxFavourableDate; extensionLevel.AveragePostHitAdverseExcursion = postHitMaxAdverseTotal / hitCount; extensionLevel.HighestPostHitAdverseExcursion = highestPostHitMaxAdverse; extensionLevel.DateOfHighestPostHitAdverseExcursion = highestPostHitMaxAdverseDate; } } }