From 28abdb15a238dd4887966cde61699752b84024ec Mon Sep 17 00:00:00 2001 From: DiTus Date: Sun, 1 Mar 2026 22:25:59 +0100 Subject: [PATCH] fixed: always update timestamp from current data, not stale cache --- .../static/js/ui/signals-calculator.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/api/dashboard/static/js/ui/signals-calculator.js b/src/api/dashboard/static/js/ui/signals-calculator.js index 30c41d1..533c6a4 100644 --- a/src/api/dashboard/static/js/ui/signals-calculator.js +++ b/src/api/dashboard/static/js/ui/signals-calculator.js @@ -107,6 +107,7 @@ function calculateHistoricalCrossovers(activeIndicators, candles) { // Find the most recent crossover by going backwards from the newest candle // candles are sorted oldest first, newest last let lastCrossoverTimestamp = null; + let lastSignalType = null; for (let i = candles.length - 1; i > 0; i--) { const candle = candles[i]; // newer candle @@ -130,18 +131,36 @@ function calculateHistoricalCrossovers(activeIndicators, candles) { // SELL signal: price crossed from above to below MA if (priceAbovePrev && !priceAboveNow) { lastCrossoverTimestamp = candle.time; + lastSignalType = 'sell'; break; } // BUY signal: price crossed from below to above MA if (!priceAbovePrev && priceAboveNow) { lastCrossoverTimestamp = candle.time; + lastSignalType = 'buy'; break; } } + // Always update the timestamp based on current data + // If crossover found use that time, otherwise use last candle time if (lastCrossoverTimestamp) { - console.log(`[HistoricalCross] ${indicatorType}: Found crossover at ${new Date(lastCrossoverTimestamp * 1000).toLocaleString()}`); + console.log(`[HistoricalCross] ${indicatorType}: Found ${lastSignalType} crossover at ${new Date(lastCrossoverTimestamp * 1000).toLocaleString()}`); indicator.lastSignalTimestamp = lastCrossoverTimestamp; + indicator.lastSignalType = lastSignalType; + } else { + // No crossover found - use last candle time + const lastCandleTime = candles[candles.length - 1]?.time; + if (lastCandleTime) { + // Determine current signal direction + const lastResult = results[results.length - 1]; + const ma = lastResult?.ma !== undefined ? lastResult.ma : lastResult; + if (ma !== undefined) { + const isAbove = candles[candles.length - 1].close > ma; + indicator.lastSignalType = isAbove ? 'buy' : 'sell'; + indicator.lastSignalTimestamp = lastCandleTime; + } + } } }); }