- Enhanced the `UserIndicator` class to include an optional `timeframe` attribute for custom indicator timeframes. - Updated the `get_indicator_data` method in `MarketDataIntegrator` to fetch and calculate indicators based on the specified timeframe, ensuring proper data alignment and handling. - Modified the `ChartBuilder` to pass the correct DataFrame for plotting indicators with different timeframes. - Added UI elements in the indicator modal for selecting timeframes, improving user experience. - Updated relevant JSON templates to include the new `timeframe` field for all indicators. - Refactored the `prepare_chart_data` function to ensure it returns a DataFrame with a `DatetimeIndex` for consistent calculations. This commit enhances the flexibility and usability of the indicator system, allowing users to analyze data across various timeframes.
2.7 KiB
2.7 KiB
Relevant Files
config/indicators/templates/*.json- Indicator configuration templates to be updated with the newtimeframefield.components/charts/indicator_manager.py- To addtimeframeto theUserIndicatordataclass and related methods.dashboard/layouts/market_data.py- To add UI elements for selecting the indicator timeframe.dashboard/callbacks/indicators.py- To handle the newtimeframeinput 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
timeframefield to all JSON templates inconfig/indicators/templates/. - 1.2 Update the
UserIndicatordataclass incomponents/charts/indicator_manager.pyto includetimeframe: Optional[str]. - 1.3 Modify
create_indicatorinIndicatorManagerto accept atimeframeparameter. - 1.4 Update
UserIndicator.from_dictandto_dictto handle the newtimeframefield.
- 1.1 Add an optional
- 2.0 Implement Multi-Timeframe Data Fetching and Calculation
- 2.1 In
components/charts/data_integration.py, modifyget_indicator_data. - 2.2 If a custom timeframe is present, call
get_market_data_for_indicatorsto 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.
- 2.1 In
- 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.
- 3.1 After calculation, reindex the indicator DataFrame to match the
- 4.0 Update UI for Indicator Timeframe Selection
- 4.1 In
dashboard/layouts/market_data.py, add adcc.Dropdownfor 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_indicatororupdate_indicator.
- 4.1 In
- 5.0 Testing and Validation
- 5.1 Write unit tests for custom timeframe data fetching and alignment.
- 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.