TCPDashboard/tasks/tasks-indicator-timeframe-feature.md
2025-06-06 15:25:18 +08:00

2.7 KiB

Relevant Files

  • config/indicators/templates/*.json - Indicator configuration templates to be updated with the new timeframe field.
  • components/charts/indicator_manager.py - To add timeframe to the UserIndicator dataclass and related methods.
  • dashboard/layouts/market_data.py - To add UI elements for selecting the indicator timeframe.
  • dashboard/callbacks/indicators.py - To handle the new timeframe input from the UI.
  • components/charts/data_integration.py - To implement the core logic for fetching data and calculating indicators on different timeframes.
  • components/charts/builder.py - To ensure the new indicator data is correctly passed to the chart.

Notes

  • The core of the changes will be in components/charts/data_integration.py.
  • Careful data alignment (reindexing and forward-filling) will be crucial for correct visualization.

Tasks

  • 1.0 Update Indicator Configuration
    • 1.1 Add an optional timeframe field to all JSON templates in config/indicators/templates/.
    • 1.2 Update the UserIndicator dataclass in components/charts/indicator_manager.py to include timeframe: Optional[str].
    • 1.3 Modify create_indicator in IndicatorManager to accept a timeframe parameter.
    • 1.4 Update UserIndicator.from_dict and to_dict to handle the new timeframe field.
  • 2.0 Implement Multi-Timeframe Data Fetching and Calculation
    • 2.1 In components/charts/data_integration.py, modify get_indicator_data.
    • 2.2 If a custom timeframe is present, call get_market_data_for_indicators to fetch new data.
    • 2.3 If no custom timeframe is set, use the existing main_df.
    • 2.4 Pass the correct DataFrame to self.indicators.calculate.
  • 3.0 Align and Merge Indicator Data for Plotting
    • 3.1 After calculation, reindex the indicator DataFrame to match the main_df's timestamp index.
    • 3.2 Use forward-fill (ffill) to handle missing values from reindexing.
    • 3.3 Add the aligned data to indicator_data_map.
  • 4.0 Update UI for Indicator Timeframe Selection
    • 4.1 In dashboard/layouts/market_data.py, add a dcc.Dropdown for timeframe selection in the indicator modal.
    • 4.2 In dashboard/callbacks/indicators.py, update the save indicator callback to read the timeframe value.
    • 4.3 Pass the selected timeframe to indicator_manager.create_indicator or update_indicator.
  • 5.0 Testing and Validation
    • 5.1 Write unit tests for custom timeframe data fetching and alignment.
    • [xx] 5.2 Manually test creating and viewing indicators with various timeframes (higher, lower, and same as chart).
    • 5.3 Verify visual correctness and data integrity on the chart.