# Feature Specification: Histogram of Results

## 1. High-Level Goal

To create a "histogram of entry and exit condition firing totals" that provides a statistical overview of how each entry and exit condition performs over a given period and timeframe. This will help with debugging, optimization, and adapting the strategy to different timeframes. Currently thinking that we render this in a table format, but open to other visualizations as we'll have 20 entry conditions and ~12 exit conditions, a bar chart or more horizontal visualization would probably be a better use of screen space.

## 2. Key Features (User Stories)

*   As a user, I want to see a table of all entry and exit conditions.
*   For each condition, I want to see:
    *   How many times it fired in the most current run
    *   Benchmark data for the best performing previous version, this I can note manually, perhaps it gets stored in an array or other data structure
    *   The best, worst, and median price change over a certain period after it fired (e.g., 1, 5, 10 bars later).
    *   A total row at the bottom of the table that gives overall performance for the strategy, in percentage terms.
    *   An input switch for whether to display in the table entry conditions, exit conditions or both.
    *   An input switch for whether to display data for disabled conditions, the default will be to only display data for enabled conditions
*   As a user, I want to be able to store and compare these results across different timeframes (e.g., 1D vs. 12H).

## 3. Implementation Idea

A three-part architecture:

*   **`LibraryStatistics.pine`:** A new library responsible for collecting and storing the statistics for each condition. The `LibraryLongEntry` and `LibraryLongExit` libraries would call this library to log when their conditions are met.
*   **`MainStrategy.pine`:** This would initialize the `LibraryStatistics` and pass the data to it.
*   **A new Indicator script:** This would be responsible for visualizing the data from the `LibraryStatistics` in a table format. This keeps the main chart clean.

## 4. Data Collection

To start, we will focus on tracking when each condition fires, and the price action that follows. We will not worry about whether a trade was actually taken. This will give us a pure measure of the predictive power of each signal.

## 5. Adaptive Display

To make the best use of the limited screen space in the TradingView indicator panel, the display will adapt based on the number of enabled conditions.

*   **Detailed Card View:** When only one entry or exit condition is enabled, the indicator will display a detailed "card" for that condition. This card will show all the metrics, including firings, benchmark data, and detailed gain/loss statistics.

*   **Summary Bar Chart View:** When multiple entry or exit conditions are enabled, the indicator will switch to a more compact, summary view. This view will display a horizontal bar chart showing the name of each enabled condition and its total number of firings. The color of the bar can be used to represent the median gain/loss for that condition, providing a quick visual cue of its performance.