- 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.
38 lines
2.7 KiB
Markdown
38 lines
2.7 KiB
Markdown
## 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
|
|
|
|
- [x] 1.0 Update Indicator Configuration
|
|
- [x] 1.1 Add an optional `timeframe` field to all JSON templates in `config/indicators/templates/`.
|
|
- [x] 1.2 Update the `UserIndicator` dataclass in `components/charts/indicator_manager.py` to include `timeframe: Optional[str]`.
|
|
- [x] 1.3 Modify `create_indicator` in `IndicatorManager` to accept a `timeframe` parameter.
|
|
- [x] 1.4 Update `UserIndicator.from_dict` and `to_dict` to handle the new `timeframe` field.
|
|
- [x] 2.0 Implement Multi-Timeframe Data Fetching and Calculation
|
|
- [x] 2.1 In `components/charts/data_integration.py`, modify `get_indicator_data`.
|
|
- [x] 2.2 If a custom timeframe is present, call `get_market_data_for_indicators` to fetch new data.
|
|
- [x] 2.3 If no custom timeframe is set, use the existing `main_df`.
|
|
- [x] 2.4 Pass the correct DataFrame to `self.indicators.calculate`.
|
|
- [x] 3.0 Align and Merge Indicator Data for Plotting
|
|
- [x] 3.1 After calculation, reindex the indicator DataFrame to match the `main_df`'s timestamp index.
|
|
- [x] 3.2 Use forward-fill (`ffill`) to handle missing values from reindexing.
|
|
- [x] 3.3 Add the aligned data to `indicator_data_map`.
|
|
- [x] 4.0 Update UI for Indicator Timeframe Selection
|
|
- [x] 4.1 In `dashboard/layouts/market_data.py`, add a `dcc.Dropdown` for timeframe selection in the indicator modal.
|
|
- [x] 4.2 In `dashboard/callbacks/indicators.py`, update the save indicator callback to read the timeframe value.
|
|
- [x] 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.
|
|
- [ ] 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. |