fix pivots - WORKING PIVOTS!
This commit is contained in:
@@ -18,6 +18,7 @@ from dash import Dash, html
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import json
|
||||
import pandas as pd
|
||||
|
||||
# Import core components from main system
|
||||
try:
|
||||
@@ -197,6 +198,70 @@ class AnnotationDashboard:
|
||||
storage_thread = threading.Thread(target=enable_storage, daemon=True)
|
||||
storage_thread.start()
|
||||
|
||||
def _get_pivot_markers_for_timeframe(self, symbol: str, timeframe: str, df: pd.DataFrame) -> dict:
|
||||
"""
|
||||
Get pivot markers for a specific timeframe
|
||||
Returns dict with indices mapping to pivot info for that candle
|
||||
"""
|
||||
try:
|
||||
if not self.data_provider:
|
||||
return {}
|
||||
|
||||
# Get Williams pivot levels for this timeframe
|
||||
pivot_levels = self.data_provider.get_williams_pivot_levels(
|
||||
symbol=symbol,
|
||||
base_timeframe=timeframe,
|
||||
limit=len(df)
|
||||
)
|
||||
|
||||
if not pivot_levels:
|
||||
return {}
|
||||
|
||||
# Build a map of timestamp -> pivot info
|
||||
pivot_map = {}
|
||||
|
||||
# For each level (1-5), find the last high and last low pivot
|
||||
for level_num, trend_level in pivot_levels.items():
|
||||
if not hasattr(trend_level, 'pivot_points') or not trend_level.pivot_points:
|
||||
continue
|
||||
|
||||
# Find last high and last low for this level
|
||||
last_high = None
|
||||
last_low = None
|
||||
|
||||
for pivot in trend_level.pivot_points:
|
||||
if pivot.pivot_type == 'high':
|
||||
last_high = pivot
|
||||
elif pivot.pivot_type == 'low':
|
||||
last_low = pivot
|
||||
|
||||
# Add to pivot map
|
||||
if last_high:
|
||||
ts_str = last_high.timestamp.strftime('%Y-%m-%d %H:%M:%S')
|
||||
if ts_str not in pivot_map:
|
||||
pivot_map[ts_str] = {'highs': [], 'lows': []}
|
||||
pivot_map[ts_str]['highs'].append({
|
||||
'level': level_num,
|
||||
'price': last_high.price,
|
||||
'strength': last_high.strength
|
||||
})
|
||||
|
||||
if last_low:
|
||||
ts_str = last_low.timestamp.strftime('%Y-%m-%d %H:%M:%S')
|
||||
if ts_str not in pivot_map:
|
||||
pivot_map[ts_str] = {'highs': [], 'lows': []}
|
||||
pivot_map[ts_str]['lows'].append({
|
||||
'level': level_num,
|
||||
'price': last_low.price,
|
||||
'strength': last_low.strength
|
||||
})
|
||||
|
||||
return pivot_map
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting pivot markers for {timeframe}: {e}")
|
||||
return {}
|
||||
|
||||
def _setup_routes(self):
|
||||
"""Setup Flask routes"""
|
||||
|
||||
@@ -333,6 +398,9 @@ class AnnotationDashboard:
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
# Get pivot points for this timeframe
|
||||
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
|
||||
|
||||
# Convert to format suitable for Plotly
|
||||
chart_data[timeframe] = {
|
||||
'timestamps': df.index.strftime('%Y-%m-%d %H:%M:%S').tolist(),
|
||||
@@ -340,7 +408,8 @@ class AnnotationDashboard:
|
||||
'high': df['high'].tolist(),
|
||||
'low': df['low'].tolist(),
|
||||
'close': df['close'].tolist(),
|
||||
'volume': df['volume'].tolist()
|
||||
'volume': df['volume'].tolist(),
|
||||
'pivot_markers': pivot_markers # Optional: only present if pivots exist
|
||||
}
|
||||
|
||||
# Get pivot bounds for the symbol
|
||||
@@ -569,13 +638,17 @@ class AnnotationDashboard:
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
# Get pivot markers for this timeframe
|
||||
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
|
||||
|
||||
chart_data[timeframe] = {
|
||||
'timestamps': df.index.strftime('%Y-%m-%d %H:%M:%S').tolist(),
|
||||
'open': df['open'].tolist(),
|
||||
'high': df['high'].tolist(),
|
||||
'low': df['low'].tolist(),
|
||||
'close': df['close'].tolist(),
|
||||
'volume': df['volume'].tolist()
|
||||
'volume': df['volume'].tolist(),
|
||||
'pivot_markers': pivot_markers # Optional: only present if pivots exist
|
||||
}
|
||||
logger.info(f"Refreshed {timeframe}: {len(df)} candles")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user