4.2 KiB
4.2 KiB
Pivot Points Debugging Improvements
Issue
Live charts are updating correctly, but pivot points stop being drawn after the first 2 pivot points are detected.
Debugging Improvements Added
1. Enhanced Logging ✅
File: ANNOTATE/web/static/js/chart_manager.js
Added detailed console logging:
- Pivot recalculation attempts with candle counts
- Throttling messages when calls are too frequent
- Before/after pivot marker counts
- Chart redraw status messages
- Warnings when charts or data are missing
2. Pivot Recalculation Throttling ✅
Problem: Pivot recalculation might be called too frequently with live updates Solution: Added 5-second throttling per timeframe
// Throttle pivot recalculation (max once every 5 seconds per timeframe)
const now = Date.now();
const lastCall = this.pivotRecalcThrottle[timeframe] || 0;
if (now - lastCall < 5000) {
console.log(`[${timeframe}] Throttling pivot recalculation`);
return;
}
3. Debug Methods ✅
Added manual debugging methods:
// Debug method to manually trigger pivot recalculation
debugRecalculatePivots(timeframe)
// Debug method to check pivot status
debugPivotStatus()
Usage in browser console:
// Check current pivot status
window.appState.chartManager.debugPivotStatus();
// Manually trigger pivot recalculation for 1m chart
window.appState.chartManager.debugRecalculatePivots('1m');
4. API Test Script ✅
File: test_pivot_api.py
Tests the backend pivot recalculation API:
- Calls
/api/recalculate-pivotsdirectly - Shows number of pivot markers returned
- Displays sample pivot data
- Verifies API is working correctly
Potential Root Causes
1. Throttling Too Aggressive
- 5-second throttling might prevent updates when new pivots form
- Check: Look for throttling messages in console
2. Backend API Issues
- Data provider might not have enough data
- Williams Market Structure calculation might be failing
- Check: Run
python test_pivot_api.pyto test API directly
3. Chart Redraw Issues
- Pivot shapes/annotations might not be updating correctly
- Display toggles might be hiding pivots
- Check: Look for redraw messages and toggle status
4. Data Synchronization
- Live data updates might not trigger pivot recalculation
- New candles might not be detected properly
- Check: Look for "NEW candles" vs "updated candles" messages
Debugging Steps
1. Check Console Logs
Look for these messages in browser console:
[1m] Recalculating pivots with 150 candles...
[1m] Pivots updated: 5 → 7 pivot candles
[1m] Redrawing chart with pivots...
2. Check Throttling
If you see throttling messages, pivots might be blocked:
[1m] Throttling pivot recalculation (last call 3s ago)
3. Manual Debug
Use debug methods in browser console:
// Check status
window.appState.chartManager.debugPivotStatus();
// Force recalculation
window.appState.chartManager.debugRecalculatePivots('1m');
4. Test Backend API
Run the test script:
python test_pivot_api.py
5. Check Display Toggles
Verify pivots are enabled:
console.log(window.appState.chartManager.displayToggles.pivots); // Should be true
Expected Behavior After Fix
Live Pivot Updates Should:
- ✅ Detect New Candles - Log when new candles are added
- ✅ Trigger Recalculation - Call pivot API when needed (but throttled)
- ✅ Update Markers - Show new pivot count in logs
- ✅ Redraw Charts - Update visual pivot lines and dots
- ✅ Respect Toggles - Only show pivots if enabled
Console Should Show:
[1m] Chart update: 0 updated, 1 new candles, total: 151
[1m] Recalculating pivots with 151 candles...
[1m] Pivots updated: 5 → 6 pivot candles
[1m] Redrawing chart with pivots...
Next Steps
- Monitor Console - Check for pivot recalculation messages
- Test API - Verify backend pivot calculation works
- Adjust Throttling - Reduce throttle time if needed
- Check Data Flow - Ensure new candles trigger recalculation
- Verify Display - Confirm pivots are visible after redraw
The debugging improvements should help identify exactly where the pivot update process is failing! 🔍