 # Feature Specification: Neural Activation Model for Signals
 
 **Status**: Draft
 **Input**: User concept for a weighted, score-based signal system.
 
 ---
 
 ## 1. High-Level Goal
 
 To evolve the strategy's signal generation from a purely boolean system (`TRUE`/`FALSE`) to a more nuanced, continuous scoring system. This "Neural Activation Model" will calculate a numeric "activation score" for each entry and exit condition by summing weighted "promoter" and "inhibitor" inputs. A signal will "fire" if its score crosses a predefined threshold, allowing for more complex and robust signal detection.
 
 This system will be developed in parallel with the existing logic, providing a new layer of information that can be used for analysis, and eventually, for live trading decisions.
 
 ## 2. Key Concepts
 
 *   **Component Input**: A raw, normalized float value from an indicator (e.g., RSI value from 0-100, MACD slope).
 *   **Activation Score**: The final numeric value for a given signal, calculated as the weighted sum of its component inputs.
 *   **Normalization Function**: A function that maps a raw indicator value to a consistent range (e.g., -1.0 to 1.0). **Crucially, this mapping is not always linear.** It can be designed to reflect specific logic, such as a bell curve where values in a "sweet spot" are highly positive, while values at the extremes (e.g., "overbought") become negative.
 *   **Promoter**: A component input that positively contributes to the activation score (has a positive weight). A strong promoter might be an RSI value moving into a bullish regime.
 *   **Inhibitor**: A component input that negatively contributes to the activation score (has a negative weight). A strong inhibitor might be a bearish market regime filter.
 *   **Weight**: A user-configurable `input` value that determines the influence of a specific component input on the final score.
 *   **Threshold**: The value the `Activation Score` must exceed for the signal to be considered "active" or "firing" (e.g., `> 1.0`).
 
 ## 3. User Scenarios
 
 *   As a strategist, I want to define a long entry signal as a weighted sum of its components, so that a signal can be triggered by either one very strong promoter or a combination of several weaker promoters.
 *   As a strategist, I want to incorporate inhibitory signals that can veto or suppress an entry, even if promoter conditions are met.
 *   As a strategist, I want to visualize the `Activation Score` for each signal on the chart to understand its behavior and tune its components more effectively.
 *   As a strategist, I want to easily adjust the weights of each component to optimize the signal's performance during backtesting.
 
 ## 4. Phased Implementation Plan
 
 This is a significant architectural addition. It should be implemented in phases to manage complexity and risk.
 
 ### Phase 1: Proof of Concept (Single Entry Condition)
 
 **Objective**: Implement the full architecture for a single, well-understood long entry condition.
 
 1.  **Select a Condition**: Choose a simple, multi-part condition from `LibraryLongEntry.pine` (e.g., a condition that combines RSI, Stochastic, and MACD).
 2.  **Deconstruct**: Identify the raw numerical inputs that feed into the current boolean logic.
 3.  **Normalize Inputs**: Create a helper function in `LibraryUtility.pine` to normalize these raw values into a consistent range (e.g., -1.0 to 1.0), where positive values are bullish and negative are bearish. This is a critical step for weighting.
 4.  **Create a Scoring Function**: In `LibraryLongEntry.pine`, create a new function `f_calculateActivation_...()` that:
     *   Takes the normalized component inputs.
     *   Takes new `input.float` weights for each component.
     *   Calculates and returns the final `Activation Score`.
 5.  **Visualize**: In a new, dedicated indicator script (`IndicatorActivationScores.pine`), call the new scoring function and plot the `Activation Score` over time, along with a horizontal line for the `Threshold`. This provides immediate visual feedback for tuning.
 
 ### Phase 2: Expansion and Refinement
 
 **Objective**: Expand the model to cover more conditions and build tools for analysis.
 
 1.  **Expand to More Conditions**: Apply the pattern from Phase 1 to several more entry and exit conditions, creating a library of activation scores.
 2.  **Develop Analysis Tools**: Enhance the `IndicatorActivationScores.pine` script to:
     *   Display a table of all component weights and their real-time values.
     *   Highlight when a score crosses its threshold.
     *   Compare the "activation-based" signal with the original "boolean-based" signal.
    *   **Range Analysis**: Add tools to analyze the statistical distribution of unbounded component inputs (like MACD slope) to help determine their effective operational range for normalization. This is a prerequisite for effective tuning.
 
 ### Phase 3: Integration with Strategy Logic
 
 **Objective**: Allow the new activation scores to influence the strategy's trading decisions.
 
 1.  **Create a "Shadow Trading" Mode**: Add an input to `MainStrategy.pine` that allows it to generate hypothetical trades based on the new activation scores, but without executing them. Log these "shadow" trades to the chart.
 2.  **Performance Comparison**: Compare the performance of the "shadow" strategy against the baseline strategy to validate the effectiveness of the new model.
 3.  **Hybrid Mode**: Introduce a new mode where a trade is only taken if BOTH the original boolean condition AND the new activation score are met. This could serve as a high-conviction filter.
 4.  **Full Replacement (Optional)**: If the new model proves to be significantly superior and more robust, a final phase could involve fully replacing the old boolean logic with the new activation-based system.
 
 ---
 
 ## 5. Tuning Methodology
 
 The effectiveness of the Neural Activation Model is entirely dependent on finding optimal values for the component weights. The architecture will be designed to support a progressively sophisticated tuning methodology.
 
 ### Stage 1: Manual Tuning & Visualization
 
 *   **Method**: The strategist will manually adjust the `input.float` values for each weight directly in the strategy's settings.
 *   **Feedback Loop**: The primary tool for this stage is the `IndicatorActivationScores.pine` script. By observing how the `Activation Score` plot changes in response to weight adjustments, the strategist can build an intuitive understanding of how different components influence the signal. The goal is to visually align the score's peaks with desirable entry/exit points on the chart.
 *   **Architectural Support**: The architecture must support this by:
    *   Using `input.float` for all weights.
    *   Providing a dedicated visualization indicator.
    *   Designing flexible normalization functions that can be configured to be linear, bell-curved, or otherwise non-linear to capture complex logic like "overbought".

 ---
 
 This plan establishes a clear, incremental path to developing a more sophisticated and potentially more profitable signal generation system, starting with a low-risk proof of concept and building towards full integration.