> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# color functions

> Reference for the 7 functions (28 entries with overloads) of the color namespace: color.a, color.b, color.from_gradient, color.g and 3 more, each with its definition and an example.

> [!NOTE]
>
> Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: color · Entries: 29

## `color` (library)

**Definition**

Seven functions: `color.new` and `color.rgb` build a colour, `color.from_gradient` builds one between two colours, and `color.r`, `color.g`, `color.b` and `color.a` read one apart. Seventeen named colour constants sit alongside them.

Seven is the whole namespace. There is no separate transparency function — set opacity with `color.new` on a colour you already have. `color.new`, `color.r`, `color.g`, `color.b` and `color.a` return `na` when the colour they are given is `na`.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color Library Example", overlay=true)
// Green when rising, red when falling, stronger with bigger moves
change = math.abs(close - close[1]) / talib.atr(14)
base = close >= close[1] ? color.green : color.red
bgcolor(color.new(base, math.min(change, 1) * 0.4))
```

## `color.a` (function, overload 1)

**Definition**

Reads the opacity of a colour.

Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.a(const color color) → const float
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `const color` | yes | Color. |

**Returns**

`const float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.a Example", overlay=false)
c = color.new(color.green, 0.4)
plot(color.a(c), title="Opacity (0.4)", color=color.green)
```

## `color.a` (function, overload 2)

**Definition**

Reads the opacity of a colour.

Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.a(input color color) → input float
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `input color` | yes | Color. |

**Returns**

`input float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.a Example", overlay=false)
c = color.new(color.green, 0.4)
plot(color.a(c), title="Opacity (0.4)", color=color.green)
```

## `color.a` (function, overload 3)

**Definition**

Reads the opacity of a colour.

Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.a(simple color color) → simple float
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `simple color` | yes | Color. |

**Returns**

`simple float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.a Example", overlay=false)
c = color.new(color.green, 0.4)
plot(color.a(c), title="Opacity (0.4)", color=color.green)
```

## `color.a` (function, overload 4)

**Definition**

Reads the opacity of a colour.

Reading is asymmetric with writing: this one returns a fraction from 0 to 1, while the three component functions return whole numbers from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.a(series color color) → series float
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `series color` | yes | Color. |

**Returns**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.a Example", overlay=false)
c = color.new(color.green, 0.4)
plot(color.a(c), title="Opacity (0.4)", color=color.green)
```

## `color.b` (function, overload 1)

**Definition**

Reads the blue component of a colour.

Its result is an int from 0 to 255, as with red and green.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.b(const color color) → const int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `const color` | yes | Color. |

**Returns**

`const int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.b Example", overlay=false)
c = color.rgb(40, 120, 220)
plot(color.b(c), title="Blue Component (220)", color=color.blue)
```

## `color.b` (function, overload 2)

**Definition**

Reads the blue component of a colour.

Its result is an int from 0 to 255, as with red and green.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.b(input color color) → input int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `input color` | yes | Color. |

**Returns**

`input int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.b Example", overlay=false)
c = color.rgb(40, 120, 220)
plot(color.b(c), title="Blue Component (220)", color=color.blue)
```

## `color.b` (function, overload 3)

**Definition**

Reads the blue component of a colour.

Its result is an int from 0 to 255, as with red and green.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.b(simple color color) → simple int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `simple color` | yes | Color. |

**Returns**

`simple int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.b Example", overlay=false)
c = color.rgb(40, 120, 220)
plot(color.b(c), title="Blue Component (220)", color=color.blue)
```

## `color.b` (function, overload 4)

**Definition**

Reads the blue component of a colour.

Its result is an int from 0 to 255, as with red and green.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.b(series color color) → series int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `series color` | yes | Color. |

**Returns**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.b Example", overlay=false)
c = color.rgb(40, 120, 220)
plot(color.b(c), title="Blue Component (220)", color=color.blue)
```

## `color.from_gradient` (function, overload 1)

**Definition**

Returns a color calculated from the linear gradient between bottom\_color and top\_color based on the relative position of value within the range defined by bottom\_value and top\_value.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.from_gradient(const float value, const float bottom_value, const float top_value, const color bottom_color, const color top_color) → const color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `value` | `const float` | yes | Value used to determine the position within the gradient range. |
| `bottom_value` | `const float` | yes | Lower boundary of the gradient range. |
| `top_value` | `const float` | yes | Upper boundary of the gradient range. |
| `bottom_color` | `const color` | yes | Color returned when value equals bottom\_value (or is below the range). |
| `top_color` | `const color` | yes | Color returned when value equals top\_value (or is above the range). |

**Returns**

`const color`

const color

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("from_gradient example", overlay=true)
c1 = color.from_gradient(close, low, high, color.yellow, color.lime)
c2 = color.from_gradient(talib.rsi(close, 7), 0, 100, color.rgb(255, 0, 0), color.rgb(0, 255, 0, 0.5))
bgcolor(c1)
```

## `color.from_gradient` (function, overload 2)

**Definition**

Returns a color calculated from the linear gradient between bottom\_color and top\_color based on the relative position of value within the range defined by bottom\_value and top\_value.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.from_gradient(input float value, input float bottom_value, input float top_value, input color bottom_color, input color top_color) → input color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `value` | `input float` | yes | Value used to determine the position within the gradient range. |
| `bottom_value` | `input float` | yes | Lower boundary of the gradient range. |
| `top_value` | `input float` | yes | Upper boundary of the gradient range. |
| `bottom_color` | `input color` | yes | Color returned when value equals bottom\_value (or is below the range). |
| `top_color` | `input color` | yes | Color returned when value equals top\_value (or is above the range). |

**Returns**

`input color`

input color

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("from_gradient example", overlay=true)
c1 = color.from_gradient(close, low, high, color.yellow, color.lime)
c2 = color.from_gradient(talib.rsi(close, 7), 0, 100, color.rgb(255, 0, 0), color.rgb(0, 255, 0, 0.5))
bgcolor(c1)
```

## `color.from_gradient` (function, overload 3)

**Definition**

Returns a color calculated from the linear gradient between bottom\_color and top\_color based on the relative position of value within the range defined by bottom\_value and top\_value.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.from_gradient(simple float value, simple float bottom_value, simple float top_value, simple color bottom_color, simple color top_color) → simple color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `value` | `simple float` | yes | Value used to determine the position within the gradient range. |
| `bottom_value` | `simple float` | yes | Lower boundary of the gradient range. |
| `top_value` | `simple float` | yes | Upper boundary of the gradient range. |
| `bottom_color` | `simple color` | yes | Color returned when value equals bottom\_value (or is below the range). |
| `top_color` | `simple color` | yes | Color returned when value equals top\_value (or is above the range). |

**Returns**

`simple color`

simple color

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("from_gradient example", overlay=true)
c1 = color.from_gradient(close, low, high, color.yellow, color.lime)
c2 = color.from_gradient(talib.rsi(close, 7), 0, 100, color.rgb(255, 0, 0), color.rgb(0, 255, 0, 0.5))
bgcolor(c1)
```

## `color.from_gradient` (function, overload 4)

**Definition**

Returns a color calculated from the linear gradient between bottom\_color and top\_color based on the relative position of value within the range defined by bottom\_value and top\_value.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.from_gradient(series float value, series float bottom_value, series float top_value, series color bottom_color, series color top_color) → series color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `value` | `series float` | yes | Value used to determine the position within the gradient range. |
| `bottom_value` | `series float` | yes | Lower boundary of the gradient range. |
| `top_value` | `series float` | yes | Upper boundary of the gradient range. |
| `bottom_color` | `series color` | yes | Color returned when value equals bottom\_value (or is below the range). |
| `top_color` | `series color` | yes | Color returned when value equals top\_value (or is above the range). |

**Returns**

`series color`

series color

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("from_gradient example", overlay=true)
c1 = color.from_gradient(close, low, high, color.yellow, color.lime)
c2 = color.from_gradient(talib.rsi(close, 7), 0, 100, color.rgb(255, 0, 0), color.rgb(0, 255, 0, 0.5))
bgcolor(c1)
```

## `color.g` (function, overload 1)

**Definition**

Reads the green component of a colour.

Like the other two component functions, it returns a whole number from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.g(const color color) → const int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `const color` | yes | Color. |

**Returns**

`const int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.g Example", overlay=true)
c = color.new(color.red, 0)
g = color.g(c)
plot(g, title="Green component", color=color.green)
```

## `color.g` (function, overload 2)

**Definition**

Reads the green component of a colour.

Like the other two component functions, it returns a whole number from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.g(input color color) → input int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `input color` | yes | Color. |

**Returns**

`input int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.g Example", overlay=true)
c = color.new(color.red, 0)
g = color.g(c)
plot(g, title="Green component", color=color.green)
```

## `color.g` (function, overload 3)

**Definition**

Reads the green component of a colour.

Like the other two component functions, it returns a whole number from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.g(simple color color) → simple int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `simple color` | yes | Color. |

**Returns**

`simple int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.g Example", overlay=true)
c = color.new(color.red, 0)
g = color.g(c)
plot(g, title="Green component", color=color.green)
```

## `color.g` (function, overload 4)

**Definition**

Reads the green component of a colour.

Like the other two component functions, it returns a whole number from 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.g(series color color) → series int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `series color` | yes | Color. |

**Returns**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.g Example", overlay=true)
c = color.new(color.red, 0)
g = color.g(c)
plot(g, title="Green component", color=color.green)
```

## `color.new` (function, overload 1)

**Definition**

Takes a colour and an opacity, and returns that colour at that opacity.

Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example `opacity 50 is outside 0–1; 1 is solid`.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.new(const color color, const float alpha) → const color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `const color` | yes | The base color (e.g., color.red, #00ff7f, color.rgb(255, 0, 0)). |
| `alpha` | `const float` | yes | Opacity, from 0 to 1, where 1 is solid and 0 is invisible. |

**Returns**

`const color`

**Notes**

* `alpha` is an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warning `opacity 50 is outside 0–1; 1 is solid`.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.new Example", overlay=true)
c = color.new(color.blue, 0.3)
bgcolor(c)
```

## `color.new` (function, overload 2)

**Definition**

Takes a colour and an opacity, and returns that colour at that opacity.

Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example `opacity 50 is outside 0–1; 1 is solid`.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.new(input color color, input float alpha) → input color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `input color` | yes | The base color (e.g., color.red, #00ff7f, color.rgb(255, 0, 0)). |
| `alpha` | `input float` | yes | Opacity, from 0 to 1, where 1 is solid and 0 is invisible. |

**Returns**

`input color`

**Notes**

* `alpha` is an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warning `opacity 50 is outside 0–1; 1 is solid`.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.new Example", overlay=true)
c = color.new(color.blue, 0.3)
bgcolor(c)
```

## `color.new` (function, overload 3)

**Definition**

Takes a colour and an opacity, and returns that colour at that opacity.

Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example `opacity 50 is outside 0–1; 1 is solid`.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.new(simple color color, simple float alpha) → simple color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `simple color` | yes | The base color (e.g., color.red, #00ff7f, color.rgb(255, 0, 0)). |
| `alpha` | `simple float` | yes | Opacity, from 0 to 1, where 1 is solid and 0 is invisible. |

**Returns**

`simple color`

**Notes**

* `alpha` is an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warning `opacity 50 is outside 0–1; 1 is solid`.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.new Example", overlay=true)
c = color.new(color.blue, 0.3)
bgcolor(c)
```

## `color.new` (function, overload 4)

**Definition**

Takes a colour and an opacity, and returns that colour at that opacity.

Opacity runs from 0 to 1, where 1 is solid and 0 invisible. A value outside the range is clamped to it rather than rejected. A literal or constant value outside the range gets a warning, for example `opacity 50 is outside 0–1; 1 is solid`.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.new(series color color, series float alpha) → series color
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `series color` | yes | The base color (e.g., color.red, #00ff7f, color.rgb(255, 0, 0)). |
| `alpha` | `series float` | yes | Opacity, from 0 to 1, where 1 is solid and 0 is invisible. |

**Returns**

`series color`

**Notes**

* `alpha` is an opacity from 0 to 1, where 1 is solid and 0 is invisible. It is not a transparency from 0 to 100. A literal or constant value outside 0 to 1 compiles with the warning `opacity 50 is outside 0–1; 1 is solid`.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.new Example", overlay=true)
c = color.new(color.blue, 0.3)
bgcolor(c)
```

## `color.r` (function, overload 1)

**Definition**

Reads the red component back out of a colour.

The figure comes back on the scale it went in on, 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.r(const color color) → const int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `const color` | yes | Color. |

**Returns**

`const int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.r Example", overlay=false)
c = close > open ? color.lime : color.red
plot(color.r(c), title="Red Component", color=color.red)
```

## `color.r` (function, overload 2)

**Definition**

Reads the red component back out of a colour.

The figure comes back on the scale it went in on, 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.r(input color color) → input int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `input color` | yes | Color. |

**Returns**

`input int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.r Example", overlay=false)
c = close > open ? color.lime : color.red
plot(color.r(c), title="Red Component", color=color.red)
```

## `color.r` (function, overload 3)

**Definition**

Reads the red component back out of a colour.

The figure comes back on the scale it went in on, 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.r(simple color color) → simple int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `simple color` | yes | Color. |

**Returns**

`simple int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.r Example", overlay=false)
c = close > open ? color.lime : color.red
plot(color.r(c), title="Red Component", color=color.red)
```

## `color.r` (function, overload 4)

**Definition**

Reads the red component back out of a colour.

The figure comes back on the scale it went in on, 0 to 255.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.r(series color color) → series int
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `color` | `series color` | yes | Color. |

**Returns**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.r Example", overlay=false)
c = close > open ? color.lime : color.red
plot(color.r(c), title="Red Component", color=color.red)
```

## `color.rgb` (function, overload 1)

**Definition**

Builds a colour from red, green and blue components, with an optional opacity.

Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.rgb(const int r, const int g, const int b, const float a) → const color
```

**Parameters**

| Name | Type | Required | Description | Default |
| - | - | - | - | - |
| `r` | `const int` | yes | Red color component. Possible values are from 0 to 255. | |
| `g` | `const int` | yes | Green color component. Possible values are from 0 to 255. | |
| `b` | `const int` | yes | Blue color component. Possible values are from 0 to 255. | |
| `a` | `const float` | no | 0 to 1, where 1 is fully opaque and 0 is fully transparent. | `1` |

**Returns**

`const color`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.rgb Example", overlay=true)
// Solid orange, and the same colour at 30% opacity
solid = color.rgb(255, 165, 0)
faded = color.rgb(255, 165, 0, 0.3)
plot(close, title="Close", color=solid, linewidth=2)
bgcolor(faded)
```

## `color.rgb` (function, overload 2)

**Definition**

Builds a colour from red, green and blue components, with an optional opacity.

Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.rgb(input int r, input int g, input int b, input float a) → input color
```

**Parameters**

| Name | Type | Required | Description | Default |
| - | - | - | - | - |
| `r` | `input int` | yes | Red color component. Possible values are from 0 to 255. | |
| `g` | `input int` | yes | Green color component. Possible values are from 0 to 255. | |
| `b` | `input int` | yes | Blue color component. Possible values are from 0 to 255. | |
| `a` | `input float` | no | 0 to 1, where 1 is fully opaque and 0 is fully transparent. | `1` |

**Returns**

`input color`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.rgb Example", overlay=true)
// Solid orange, and the same colour at 30% opacity
solid = color.rgb(255, 165, 0)
faded = color.rgb(255, 165, 0, 0.3)
plot(close, title="Close", color=solid, linewidth=2)
bgcolor(faded)
```

## `color.rgb` (function, overload 3)

**Definition**

Builds a colour from red, green and blue components, with an optional opacity.

Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.rgb(simple int r, simple int g, simple int b, simple float a) → simple color
```

**Parameters**

| Name | Type | Required | Description | Default |
| - | - | - | - | - |
| `r` | `simple int` | yes | Red color component. Possible values are from 0 to 255. | |
| `g` | `simple int` | yes | Green color component. Possible values are from 0 to 255. | |
| `b` | `simple int` | yes | Blue color component. Possible values are from 0 to 255. | |
| `a` | `simple float` | no | 0 to 1, where 1 is fully opaque and 0 is fully transparent. | `1` |

**Returns**

`simple color`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.rgb Example", overlay=true)
// Solid orange, and the same colour at 30% opacity
solid = color.rgb(255, 165, 0)
faded = color.rgb(255, 165, 0, 0.3)
plot(close, title="Close", color=solid, linewidth=2)
bgcolor(faded)
```

## `color.rgb` (function, overload 4)

**Definition**

Builds a colour from red, green and blue components, with an optional opacity.

Two scales meet in one call: the components run from 0 to 255 and the opacity from 0 to 1. Leave the opacity out and the colour is solid; components and opacity are both clamped to their range.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
color.rgb(series int r, series int g, series int b, series float a) → series color
```

**Parameters**

| Name | Type | Required | Description | Default |
| - | - | - | - | - |
| `r` | `series int` | yes | Red color component. Possible values are from 0 to 255. | |
| `g` | `series int` | yes | Green color component. Possible values are from 0 to 255. | |
| `b` | `series int` | yes | Blue color component. Possible values are from 0 to 255. | |
| `a` | `series float` | no | 0 to 1, where 1 is fully opaque and 0 is fully transparent. | `1` |

**Returns**

`series color`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("color.rgb Example", overlay=true)
// Solid orange, and the same colour at 30% opacity
solid = color.rgb(255, 165, 0)
faded = color.rgb(255, 165, 0, 0.3)
plot(close, title="Close", color=solid, linewidth=2)
bgcolor(faded)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.