SetIndexVisibility
Sets the visibility of a buffer programmatically based on custom indicator logic.
Syntax
SetIndexVisibility(index: number, isVisible: boolean): voidParameters
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()(useSetIndexStyleinstead)
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
Mutually Exclusive States: Show buffer A OR buffer B, never both
Conditional Signals: Only display signals when market conditions are suitable
Quality Control: Hide unreliable data, show only when confidence is high
Mode Switching: Different displays for different market modes (trend/range/volatile)
Error Handling: Hide buffers when calculations are invalid or insufficient data
Performance Optimization: Hide complex buffers during high-frequency updates
Key Rules
SetIndexVisibility = Algorithmic decisions by the indicator
Built-in checkboxes = User preferences and basic on/off controls
Use for intelligent logic, not simple user toggles
Perfect for state machines and conditional displays
Great for data quality control and error handling
Last updated