## ADDED Requirements ### Requirement: TA-Lib pattern selection panel The system SHALL display a collapsible "TA-Lib Patterns" panel in the sidebar. The panel SHALL list all available CDL pattern functions grouped by category (single-candle, multi-candle). Each pattern SHALL have a checkbox for selection. The panel SHALL include a "Select All" / "Deselect All" toggle and a "Detect Patterns" action button. #### Scenario: Display available patterns - **WHEN** the user expands the TA-Lib Patterns panel - **THEN** all available CDL pattern names are listed with checkboxes, grouped by category, all unchecked by default #### Scenario: Select specific patterns - **WHEN** the user checks "Engulfing" and "Hammer" checkboxes - **THEN** those two patterns are selected and the "Detect Patterns" button shows the count "(2 selected)" #### Scenario: Select all patterns - **WHEN** the user clicks "Select All" - **THEN** all pattern checkboxes become checked ### Requirement: Pattern detection execution The system SHALL send selected patterns and current chart candles to the backend for detection when the user clicks "Detect Patterns". The system SHALL display a loading state during detection and show results as span annotations on the chart upon completion. #### Scenario: Run pattern detection - **WHEN** the user has selected patterns and clicks "Detect Patterns" - **THEN** the system sends current chart candles and selected pattern names to `POST /api/patterns/detect`, shows a loading spinner, and upon response saves returned annotations to the database via `POST /api/span-annotations` #### Scenario: No patterns selected - **WHEN** the user clicks "Detect Patterns" with no patterns selected - **THEN** the button is disabled and nothing happens #### Scenario: No chart loaded - **WHEN** the user clicks "Detect Patterns" with no chart loaded - **THEN** the system shows an error message "Load a chart first" ### Requirement: Pattern results as span annotations The system SHALL save detected patterns as span annotations with `source: "talib"`. Each annotation SHALL include the pattern label (e.g., "Bullish Engulfing"), confidence from TA-Lib, start_time, and end_time. The annotations SHALL appear immediately on the chart after detection. #### Scenario: Pattern saved as span annotation - **WHEN** TA-Lib detects a "Bullish Engulfing" pattern at candles T10-T12 - **THEN** a span annotation is created with `label: "Bullish Engulfing"`, `source: "talib"`, `start_time: T10`, `end_time: T12`, and it renders on the chart #### Scenario: Multiple patterns detected - **WHEN** detection finds 5 Engulfing and 3 Hammer patterns - **THEN** 8 span annotations are created, each with appropriate label and timestamps ### Requirement: TA-Lib annotation management The system SHALL allow users to bulk delete all TA-Lib-generated annotations or delete them by pattern type. The panel SHALL show a count of detected patterns and a "Clear All TA-Lib" button. Individual TA-Lib annotations SHALL also be deletable from the SpanAnnotationList. #### Scenario: Bulk delete all TA-Lib annotations - **WHEN** the user clicks "Clear All TA-Lib" - **THEN** all span annotations with `source: "talib"` for the current chart are deleted #### Scenario: Delete by pattern type - **WHEN** the user clicks the delete icon next to "Engulfing" in the results summary - **THEN** all span annotations with `source: "talib"` and label containing "Engulfing" for the current chart are deleted #### Scenario: Detection results summary - **WHEN** pattern detection completes with results - **THEN** the panel shows a summary: total patterns found, grouped by pattern name with counts (e.g., "Engulfing: 5, Hammer: 3")