 # Feature Specification: 8hr Long Exit Optimization
 
 **Feature Branch**: `feature/8hr-long-exit-optimization`
 **Created**: 2025-09-16
 **Status**: Draft
 **Input**: User description: "a feature that optimizes long exits on the 8hr timeframe using charting technical analysis techniques looking at the three previous candles"
 
 ---
 
 ## ⚡ Quick Guidelines
 - ✅ Focus on WHAT users need and WHY
 - ❌ Avoid HOW to implement (no tech stack, APIs, code structure)
 - 👥 Written for business stakeholders, not developers
 
 ---
 
 ## User Scenarios & Testing *(mandatory)*
 
 ### Primary User Story
 As a trader using the 8-hour timeframe, I want the strategy to automatically exit long positions based on classic bearish short-term candlestick patterns to protect profits and reduce drawdowns before a larger downturn occurs.
 
 ### Acceptance Scenarios
 1.  **Given** the strategy is in a long position on the 8hr chart, **When** a "Three Black Crows" pattern completes on the last three candles, **Then** the strategy MUST trigger a long exit signal.
 2.  **Given** the strategy is in a long position on the 8hr chart, **When** a "Bearish Engulfing" pattern completes on the last two candles, **Then** the strategy MUST trigger a long exit signal.
 3.  **Given** the strategy is in a long position on the 8hr chart, **When** an "Evening Star" pattern completes on the last three candles, **Then** the strategy MUST trigger a long exit signal.
 4.  **Given** the strategy is NOT in a long position, **When** any of the specified bearish patterns appear, **Then** no action should be taken.
 
 ### Edge Cases
 - What happens if a bearish pattern forms, but other strong long-entry conditions are also present? Does the exit take priority?
 - How does the system handle significant wicks or doji candles within a pattern? Are there volume or body-size thresholds?
 - What is the behavior if this new exit condition fires on the same bar as an existing exit condition?
 
 ## Requirements *(mandatory)*
 
 ### Functional Requirements
 - **FR-001**: The system MUST be able to detect a "Three Black Crows" candlestick pattern.
 - **FR-002**: The system MUST be able to detect a "Bearish Engulfing" candlestick pattern.
 - **FR-003**: The system MUST be able to detect an "Evening Star" candlestick pattern.
 - **FR-004**: A new long exit condition, `longExit_8hrCandlePattern`, MUST be created that is triggered when any of the above patterns are detected.
 - **FR-005**: A new input switch, `i_enable_longExit_8hrCandlePattern`, MUST be created to allow users to enable or disable this feature. It should be disabled by default.
 - **FR-006**: This new exit logic MUST only be active when the chart's timeframe is set to 8 hours ("480" in TradingView).
 - **FR-007**: The system MUST provide a reason in the trade log, such as "Exit: 8hr Three Black Crows", when this condition triggers an exit.
 - **FR-008**: The pattern detection logic MUST include quality filters to avoid triggering on ambiguous or weak patterns (e.g., dojis, candles with very small bodies relative to their wicks).
 
 ### Key Entities *(include if feature involves data)*
 - **Candlestick Pattern**: Represents a recognized bearish pattern.
   - **Attributes**: Name (e.g., "Three Black Crows"), Number of candles (2 or 3), Detection logic.
 
 ---
 
 ## Review & Acceptance Checklist
 
 ### Content Quality
 - [X] No implementation details (languages, frameworks, APIs)
 - [X] Focused on user value and business needs
 - [X] Written for non-technical stakeholders
 - [X] All mandatory sections completed
 
 ### Requirement Completeness
 - [ ] No [NEEDS CLARIFICATION] markers remain
 - [X] Requirements are testable and unambiguous
 - [X] Success criteria are measurable
 - [X] Scope is clearly bounded
 - [X] Dependencies and assumptions identified
 