From 4b33b01707757389951a3cb045feb96053f78206 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Mon, 24 Nov 2025 20:02:14 +0700 Subject: [PATCH] Update ichimoku --- .../Indicators/Trends/IchimokuKumoTrend.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Managing.Domain/Indicators/Trends/IchimokuKumoTrend.cs b/src/Managing.Domain/Indicators/Trends/IchimokuKumoTrend.cs index e04883de..dedf02be 100644 --- a/src/Managing.Domain/Indicators/Trends/IchimokuKumoTrend.cs +++ b/src/Managing.Domain/Indicators/Trends/IchimokuKumoTrend.cs @@ -74,8 +74,11 @@ public class IchimokuKumoTrend : IndicatorBase if (preCalculatedValues?.Ichimoku != null && preCalculatedValues.Ichimoku.Any()) { // Filter pre-calculated Ichimoku values to match the candles we're processing + // and ensure we have valid cloud data (non-null, non-zero values) ichimokuResults = preCalculatedValues.Ichimoku - .Where(i => i.SenkouSpanA.HasValue && i.SenkouSpanB.HasValue && candles.Any(c => c.Date == i.Date)) + .Where(i => i.SenkouSpanA.HasValue && i.SenkouSpanB.HasValue && + i.SenkouSpanA.Value != 0 && i.SenkouSpanB.Value != 0 && + candles.Any(c => c.Date == i.Date)) .ToList(); } @@ -128,8 +131,14 @@ public class IchimokuKumoTrend : IndicatorBase var candleIchimokuResults = new List(); // Map IchimokuResult to CandleIchimoku + // Only include results where we have valid cloud data foreach (var ichimoku in ichimokuList) { + // Skip if cloud data is not available (null or 0 values indicate insufficient data) + if (!ichimoku.SenkouSpanA.HasValue || !ichimoku.SenkouSpanB.HasValue || + ichimoku.SenkouSpanA.Value == 0 || ichimoku.SenkouSpanB.Value == 0) + continue; + // Find the corresponding candle var candle = candles.FirstOrDefault(c => c.Date == ichimoku.Date); if (candle == null) continue; @@ -143,8 +152,8 @@ public class IchimokuKumoTrend : IndicatorBase Exchange = candle.Exchange, TenkanSen = ichimoku.TenkanSen ?? 0, KijunSen = ichimoku.KijunSen ?? 0, - SenkouSpanA = ichimoku.SenkouSpanA ?? 0, - SenkouSpanB = ichimoku.SenkouSpanB ?? 0 + SenkouSpanA = ichimoku.SenkouSpanA.Value, + SenkouSpanB = ichimoku.SenkouSpanB.Value }); } @@ -161,6 +170,10 @@ public class IchimokuKumoTrend : IndicatorBase var previousCandle = mappedData[0]; foreach (var currentCandle in mappedData.Skip(1)) { + // Skip if cloud data is not available (values are 0 due to insufficient data) + if (currentCandle.SenkouSpanA == 0 || currentCandle.SenkouSpanB == 0) + continue; + // For trend assessment, check if price is above or below the cloud // The cloud is formed by Senkou Span A and Senkou Span B var cloudTop = Math.Max(currentCandle.SenkouSpanA, currentCandle.SenkouSpanB); @@ -193,6 +206,10 @@ public class IchimokuKumoTrend : IndicatorBase if (candle == null || !currentResult.SenkouSpanA.HasValue || !currentResult.SenkouSpanB.HasValue) continue; + // Skip if cloud data is not available (values are 0 due to insufficient data) + if (currentResult.SenkouSpanA.Value == 0 || currentResult.SenkouSpanB.Value == 0) + continue; + // For trend assessment, check if price is above or below the cloud // The cloud is formed by Senkou Span A and Senkou Span B var cloudTop = Math.Max(currentResult.SenkouSpanA.Value, currentResult.SenkouSpanB.Value);