SetIndexVisibility

Sets the visibility of a buffer programmatically based on custom indicator logic.

Syntax

SetIndexVisibility(index: number, isVisible: boolean): void

Parameters

  • index - A number representing the index of the buffer.

  • isVisible - A boolean indicating whether the buffer should be visible.

Return Value

This method does not return a value.

Description

The SetIndexVisibility method allows your indicator to programmatically control buffer visibility based on custom logic, calculations, or indicator states. This is NOT for basic user preferences (users already have built-in checkboxes for that), but for algorithmic decisions where the indicator itself determines what should be displayed.

When to Use SetIndexVisibility

βœ… Use SetIndexVisibility For:

  • State-based indicators - show different buffers for different market states

  • Conditional logic - only show certain buffers when specific conditions are met

  • Mutually exclusive displays - show one buffer OR another, never both

  • Data-driven visibility - hide buffers when data is invalid or insufficient

  • Dynamic switching - change what's visible based on calculations

❌ Don't Use SetIndexVisibility For:

  • Basic user preferences - users have built-in checkboxes for this

  • Simple on/off toggles - the built-in visibility controls handle this

  • Initial visibility setup in Init() (use SetIndexStyle instead)

SetIndexVisibility vs Built-in Controls

Built-in User Controls (Checkboxes)

Users can already control basic visibility:

  • βœ… "Show/Hide Main Line"

  • βœ… "Show/Hide Signal Line"

  • βœ… Basic on/off toggles

SetIndexVisibility (Custom Logic)

Use for intelligent, condition-based visibility:

  • βœ… Show uptrend buffer OR downtrend buffer (never both)

  • βœ… Hide signal when market is ranging

  • βœ… Show different buffers for different timeframes

  • βœ… Display warning buffer only when conditions are dangerous

Practical Examples

Example 1: State-Based Indicator (Trend vs Range)

Example 2: Conditional Signal Display

Example 3: Timeframe-Dependent Display

Example 4: Data Quality Control

Common Use Cases

  1. Mutually Exclusive States: Show buffer A OR buffer B, never both

  2. Conditional Signals: Only display signals when market conditions are suitable

  3. Quality Control: Hide unreliable data, show only when confidence is high

  4. Mode Switching: Different displays for different market modes (trend/range/volatile)

  5. Error Handling: Hide buffers when calculations are invalid or insufficient data

  6. Performance Optimization: Hide complex buffers during high-frequency updates

Key Rules

  1. SetIndexVisibility = Algorithmic decisions by the indicator

  2. Built-in checkboxes = User preferences and basic on/off controls

  3. Use for intelligent logic, not simple user toggles

  4. Perfect for state machines and conditional displays

  5. Great for data quality control and error handling

Last updated