trend line predictions filter

This commit is contained in:
Dobromir Popov
2025-12-10 00:53:36 +02:00
parent fadfa8c741
commit 177022e472

View File

@@ -3090,13 +3090,35 @@ class ChartManager {
targetPrice = currentPrice + priceChange; targetPrice = currentPrice + priceChange;
// Sanity check: Don't let target price go to 0 or negative // CRITICAL VALIDATION: Filter out invalid trend lines that would break chart zoom
// Don't draw if:
// 1. Target price is <= 0 or not finite
// 2. Target price is more than 10% away from current price (likely bad prediction)
// 3. Price change is too extreme (> 50% of current price)
const priceChangePercent = Math.abs((targetPrice - currentPrice) / currentPrice);
if (targetPrice <= 0 || !isFinite(targetPrice)) { if (targetPrice <= 0 || !isFinite(targetPrice)) {
console.warn('Invalid target price calculated:', targetPrice, 'using current price instead'); console.warn('Skipping trend line: Invalid target price:', targetPrice);
targetPrice = currentPrice; return; // Don't draw this trend line
} }
// Draw trend ray if (priceChangePercent > 0.10) {
console.warn('Skipping trend line: Price change too large:',
`${(priceChangePercent * 100).toFixed(1)}% (${currentPrice.toFixed(2)} -> ${targetPrice.toFixed(2)})`);
return; // Don't draw this trend line
}
// Additional check: Ensure target price is within reasonable bounds
const minReasonablePrice = currentPrice * 0.5; // 50% below
const maxReasonablePrice = currentPrice * 1.5; // 50% above
if (targetPrice < minReasonablePrice || targetPrice > maxReasonablePrice) {
console.warn('Skipping trend line: Target price out of reasonable bounds:',
`${targetPrice.toFixed(2)} (current: ${currentPrice.toFixed(2)})`);
return; // Don't draw this trend line
}
// All validations passed - draw the trend ray
shapes.push({ shapes.push({
type: 'line', type: 'line',
x0: lastTimestamp, x0: lastTimestamp,