fix display predictions only on the selected main chart

This commit is contained in:
Dobromir Popov
2025-12-10 01:18:34 +02:00
parent bf381a9649
commit e84eed2839
3 changed files with 51 additions and 28 deletions

View File

@@ -0,0 +1 @@
once there are 2 Low or 2 high Level 2 pivots AFTER the trend line prediction, we should make a trend line and do backpropagation to adjust our model predictions of trend

View File

@@ -2976,6 +2976,7 @@ class AnnotationDashboard:
'current_price': current_price, 'current_price': current_price,
'price_change': price_change, 'price_change': price_change,
'predicted_candle': predicted_candle, # This is what frontend needs! 'predicted_candle': predicted_candle, # This is what frontend needs!
'primary_timeframe': '1m', # The main timeframe the model is predicting for
'type': 'transformer_prediction' 'type': 'transformer_prediction'
} }

View File

@@ -2863,45 +2863,66 @@ class ChartManager {
/** /**
* Update model predictions on charts * Update model predictions on charts
* Draws predictions ONLY on the primary timeframe (the one the model is predicting for)
* Other timeframes are just reference data for the model
*/ */
updatePredictions(predictions) { updatePredictions(predictions) {
if (!predictions) return; if (!predictions) return;
try { try {
// Use the currently active timeframe from app state // CRITICAL: Only draw predictions on the PRIMARY timeframe
// This ensures predictions appear on the chart the user is watching (e.g., '1s') // The model uses other timeframes as reference, but predictions are for the primary timeframe only
const timeframe = window.appState?.currentTimeframes?.[0] || '1m'; const primaryTimeframe = predictions.transformer?.primary_timeframe ||
window.appState?.currentTimeframes?.[0] ||
'1m';
console.log(`[updatePredictions] Drawing predictions on primary timeframe: ${primaryTimeframe}`);
// Update only the primary timeframe
this._updatePredictionsForTimeframe(primaryTimeframe, predictions);
} catch (error) {
console.error('[updatePredictions] Error:', error);
}
}
/**
* Update predictions for a specific timeframe
* @private
*/
_updatePredictionsForTimeframe(timeframe, predictions) {
try {
const chart = this.charts[timeframe]; const chart = this.charts[timeframe];
if (!chart) { if (!chart) {
console.warn(`[updatePredictions] Chart not found for timeframe: ${timeframe}`); console.debug(`[updatePredictions] Chart not found for timeframe: ${timeframe}`);
return; return;
} }
// Throttle prediction updates to avoid flickering // Throttle prediction updates to avoid flickering
const now = Date.now(); const now = Date.now();
const lastUpdate = this.lastPredictionUpdate[timeframe] || 0; const lastUpdate = this.lastPredictionUpdate[timeframe] || 0;
// Create a simple hash of prediction data to detect actual changes // Create a simple hash of prediction data to detect actual changes
const predictionHash = JSON.stringify({ const predictionHash = JSON.stringify({
action: predictions.transformer?.action, action: predictions.transformer?.action,
confidence: predictions.transformer?.confidence, confidence: predictions.transformer?.confidence,
predicted_price: predictions.transformer?.predicted_price, predicted_price: predictions.transformer?.predicted_price,
timestamp: predictions.transformer?.timestamp timestamp: predictions.transformer?.timestamp
}); });
// Skip update if: // Skip update if:
// 1. Too soon since last update (throttle) // 1. Too soon since last update (throttle)
// 2. Predictions haven't actually changed // 2. Predictions haven't actually changed
if (now - lastUpdate < this.predictionUpdateThrottle && predictionHash === this.lastPredictionHash) { if (now - lastUpdate < this.predictionUpdateThrottle && predictionHash === this.lastPredictionHash) {
console.debug(`[updatePredictions] Skipping update (throttled or unchanged)`); console.debug(`[updatePredictions] Skipping update for ${timeframe} (throttled or unchanged)`);
return; return;
} }
this.lastPredictionUpdate[timeframe] = now; this.lastPredictionUpdate[timeframe] = now;
this.lastPredictionHash = predictionHash; this.lastPredictionHash = predictionHash;
console.log(`[updatePredictions] Timeframe: ${timeframe}, Predictions:`, predictions); console.log(`[updatePredictions] Timeframe: ${timeframe}, Predictions:`, predictions);
const plotId = chart.plotId; const plotId = chart.plotId;
const plotElement = document.getElementById(plotId); const plotElement = document.getElementById(plotId);