# Feature Specification: Plotting Strategy

## 1. High-Level Goal

To refactor the plotting logic out of the main strategy and into a set of dedicated, reusable indicators. This will improve code organization, remove the 64-plot limit constraint, and make it easier to debug and visualize the behavior of the strategy and its underlying libraries.

## 2. Key Features

*   Create a dedicated indicator for each library.
*   The indicator will have input settings to select which variables from that library to plot.
*   It will support plotting booleans as colored horizontal lines and numeric variables as lines.
*   It will make use of the data window for displaying detailed information without cluttering the chart.
*   The existing plotting code in `MainStrategy.pine` will be removed.

## 3. Implementation Plan

1.  Create a new indicator script for each library that we want to visualize.
2.  This indicator will import its corresponding library.
3.  It will then have a series of `input.bool()` switches to select which variables from that library to plot.
*   **Synchronization Requirement:** The indicator must duplicate the necessary inputs and calculations from the main strategy to function. It is a mandatory part of the workflow to keep these inputs perfectly synchronized between the strategy and the indicator to ensure the visualization is accurate. The indicator should contain the minimum logic necessary for plotting and should not introduce new calculations.
4.  The indicator will use conditional expressions to plot `na` when a plot is disabled, to work around Pine Script's limitations (e.g., `plot(i_plot_my_variable ? my_variable : na, title="My Variable")`).
5.  We will then update the libraries to expose the data that we want to plot.
6.  Use conditional coloring for numeric plots to provide at-a-glance information. For values that can be positive or negative, they should be colored green for positive/zero and red for negative (e.g., `color = my_variable >= 0 ? color.green : color.red`).
7.  Finally, we will remove the old plotting code from `MainStrategy.pine`.

## 4. Detailed Visualization Rules

To handle the complexity of visualizing many variables, especially from large libraries like `LibraryLongEntry`, the following conventions will be used.

### 4.1. Plotting Booleans on the Chart

To visualize numerous boolean conditions from a single library (e.g., `LibraryLongEntry`) without exceeding the 64-plot limit, a specific "ladder" plotting method is required. The primary goal is to maximize the number of visible conditions while maintaining clarity.

*   **Indicator Setup:** The indicator will have three new inputs to control the visualization:
    *   `i_plot_baseline`: A `float` input for the baseline value (Y-axis) of the first plot.
    *   `i_plot_increment`: A `float` input for the vertical distance between each subsequent plot.
    *   `i_plot_line_width`: An `int` input to control the thickness of the plotted lines.

*   **Plotting Logic:**
    *   Each boolean variable will be assigned a unique integer multiplier (`N`).
    *   The plot's Y-value is calculated as: `i_plot_baseline - (i_plot_increment * N)`.
    *   The plot is rendered as a horizontal line (`plot.style_linebr`) only when the boolean condition is `true`. When `false`, `na` is plotted to show nothing.

*   **Critical Optimizations for Plot Count:**
    *   **Static Colors:** The `color` argument in the `plot()` function **must be static** (e.g., `color=color.new(color.aqua, 0)`). Using a conditional expression for color (e.g., `color = condition ? color.green : color.red`) consumes an additional plot slot and must be avoided in these boolean indicators.
    *   **No Function Calls in Color:** Similarly, using a function call to determine the color (e.g., `color = f_get_color()`) will also consume an extra plot slot and **must be avoided**.
    *   **Color Assignment Strategy:** To improve readability and distinguish between the many boolean plots, assign a unique, static color to each plot. It is recommended to manually cycle through a list of distinct colors (e.g., `color.aqua`, `color.fuchsia`, `color.lime`, etc.) for each subsequent plot line. This avoids repetition and makes the chart easier to analyze.
    *   **Hide from Status Line:** The `display` argument should be set to `display.all - display.status_line`. This prevents the plot's numerical value from appearing in the chart's status line, keeping it clean.

**Example:**
```pinescript
// Plot a boolean condition using the optimized ladder method.
plot(longEntryResults.my_condition_1 ? i_plot_baseline - i_plot_increment * 1 : na, 
     title="My First Condition", 
     style=plot.style_linebr, 
     color=color.new(color.aqua, 0), 
     linewidth=i_plot_line_width, 
     display=display.all-display.status_line)

plot(longEntryResults.my_condition_2 ? i_plot_baseline - i_plot_increment * 2 : na, 
     title="My Second Condition", 
     style=plot.style_linebr, 
     color=color.new(color.fuchsia, 0), // Use a different static color
     linewidth=i_plot_line_width, 
     display=display.all-display.status_line)
```
