# SetIndexStyle

Sets the visual style for a buffer.

**Important**: This method should **only be used inside the** [**`Init()`**](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/init) **method** for initial buffer configuration.

## Syntax

```typescript
SetIndexStyle(
    bufferIndex: number,
    type: TDrawStyle,
    style: TPenStyle,
    width: number,
    clr: string,
    isVisible?: boolean
): void
```

## Parameters

* `bufferIndex` - A number representing the index of the buffer to style.
* `type` - A value from the [`TDrawStyle`](https://fto-2.gitbook.io/fto-indicators-docs/types/draw-style) enum specifying how to draw the buffer.
* `style` - A value from the [`TPenStyle`](https://fto-2.gitbook.io/fto-indicators-docs/types/pen-style)enum specifying the line style.
* `width` - A number representing the line width in pixels.
* `clr` - A string hex color value for the buffer.
* `isVisible` - (Optional) A boolean for **initial visibility setup only**. For algorithmic visibility control, use [`SetIndexVisibility`](https://fto-2.gitbook.io/fto-indicators-docs/configure_indicator/set-index-visibility) instead.

## Return Value

This method does not return a value.

## Description

The `SetIndexStyle` method sets the visual appearance of a buffer on the chart during indicator initialization. This includes the drawing style (line, histogram, etc.), line style (solid, dashed, etc.), width, color, and initial visibility.

**Usage Guidelines:**

* **Use in** [**`Init()`**](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/init) **only** - for setting up buffer appearance during indicator creation
* **For algorithmic visibility control** - use [`SetIndexVisibility`](https://fto-2.gitbook.io/fto-indicators-docs/configure_indicator/set-index-visibility) in [`Calculate()`](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/calculate) based on conditions/calculations

See [`TDrawStyle`](https://fto-2.gitbook.io/fto-indicators-docs/types/draw-style) for available drawing styles, [`TPenStyle`](https://fto-2.gitbook.io/fto-indicators-docs/types/pen-style) for line styles

## Visibility Parameter vs SetIndexVisibility

### Initial Setup (in Init())

Use the `isVisible` parameter in `SetIndexStyle` for setting the **initial visibility state**:

```typescript
public Init(): void {
    // Set initial style with visibility
    this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0000ff", true);  // Initially visible
    this.api.SetIndexStyle(1, TDrawStyle.NONE, TPenStyle.SOLID, 1, "#000000", false); // Initially hidden
}
```

### Dynamic Changes (in OnParamsChange() or Calculate())

Use `SetIndexVisibility` for **algorithmic visibility control**:

```typescript
public Calculate(index: number): void {
    // Show different buffers based on market state
    if (this.isInTrendingMarket(index)) {
        this.api.SetIndexVisibility(0, true);  // Trend buffer
        this.api.SetIndexVisibility(1, false); // Range buffer
    } else {
        this.api.SetIndexVisibility(0, false); // Trend buffer
        this.api.SetIndexVisibility(1, true);  // Range buffer
    }
}
```

## Example

```typescript
public Init(): void {
    // Initial buffer setup with visibility

    // Buffer 0: Always visible main line
    this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0000ff", true);

    // Buffer 1: Initially hidden calculation buffer
    this.api.SetIndexStyle(1, TDrawStyle.NONE, TPenStyle.SOLID, 1, "#000000", false);

    // Buffer 2: Initially hidden, will be shown conditionally
    this.api.SetIndexStyle(2, TDrawStyle.HISTOGRAM, TPenStyle.SOLID, 3, "#00ff00", false);
}

public Calculate(index: number): void {
    // Algorithmic visibility control - use SetIndexVisibility
    const signalStrength = this.calculateSignalStrength(index);
    if (signalStrength > 0.8) {
        this.api.SetIndexVisibility(2, true);  // Show strong signals only
    } else {
        this.api.SetIndexVisibility(2, false); // Hide weak signals
    }

    // DON'T do this in Calculate() or any method thats not Init():
    // this.api.SetIndexStyle(2, TDrawStyle.HISTOGRAM, TPenStyle.SOLID, 3, "#00ff00", true); // ❌ Wrong!
}
```

## Key Rules

1. **`SetIndexStyle`** = Initial setup in [`Init()`](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/init) only
2. **`SetIndexVisibility`** = Dynamic changes in [`OnParamsChange()`](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/on-params-change) or [`Calculate()`](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/calculate)
3. **Both methods control visibility**, but serve different purposes in the indicator lifecycle
