MMTMMT Docs
Built-in catalog

color reference

Color constructors, channel accessors, interpolation helpers, and named colors; channels and alpha are 0-255 and out-of-range values clamp.

Color constructors, channel accessors, interpolation helpers, and named colors; channels and alpha are 0-255 and out-of-range values clamp.

Accepted values

These named values are the complete choices accepted by parameters of each type.

ColorSpace

ValueMeaning
colorspace.rgbRGB color-scale interpolation by channel.
colorspace.hslHSL color-scale interpolation with shortest-path hue.

Easing

ValueMeaning
easing.linearLinear segment easing, leaving the local position unchanged.
easing.smoothstepSmoothstep segment easing with t*t*(3-2t).
easing.smootherstepSmootherstep segment easing with t*t*t*(t*(6t-15)+10).

Named colors

Use these constants anywhere a color value is accepted. Select a hex value to copy it.

ConstantValue
color.up
color.down
color.red
color.maroon
color.brown
color.orange
color.amber
color.yellow
color.olive
color.green
color.emerald
color.teal
color.cyan
color.lightskyblue
color.blue
color.indigo
color.navy
color.purple
color.magenta
color.pink
color.white
color.silver
color.gray
color.black
color.transparent

color.rgb

color.rgb(r: int, g: int, b: int, a: int = 255) -> color

Creates a color from red, green, blue, and opacity values.

r, g, and b each use an integer from 0 to 255. Out-of-range values are clamped to the nearest end of that range.

a sets opacity from 0 (transparent) to 255 (opaque) and defaults to 255. For example, color.rgb(17, 34, 51) equals #112233. All inputs must be non-null integers; fractions are not accepted.

Contracts

  • r: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.
  • g: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.
  • b: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.
  • a: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.

Example

script "RGB Color"
data chart = subscribe(data.ohlcv)
plot ma = plot.line(title: "MA", color: color.rgb(33, 150, 243, 192))

on chart.update {
  ma.plot(ta.sma(chart.close, 20))
}
rgb(232, 31, 89)
rgb(245, 158, 11)
rgb(22, 199, 132)
rgb(70, 107, 229)

color.withAlpha

color.withAlpha(c: color, a: int) -> color

Changes a color's opacity.

c supplies the color. a sets opacity from 0 (transparent) to 255 (opaque). It is an integer, not a percentage. Out-of-range values are clamped to 0 or 255.

Check for null or use ?? before passing a nullable color.

Contracts

  • a: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.

Example

script "Alpha Color"
data chart = subscribe(data.ohlcv)
plot closeLine = plot.line(title: "Close")

on chart.update {
  let shade = color.withAlpha(chart.close >= chart.open ? color.green : color.red, 96)
  closeLine.plot(chart.close, color: shade)
}
Alpha channel
color.blue
32
96
160
224
255

color.r

color.r(c: color) -> int

Returns the red channel from a color.

Returns the red value of c as an integer from 0 to 255. Check for null or use ?? before passing a nullable color.

Example

script "Red Channel"
data chart = subscribe(data.ohlcv)

on chart.update {
  let shade = chart.close >= chart.open ? color.green : color.red
  let red = color.r(shade)
}

color.g

color.g(c: color) -> int

Returns the green channel from a color.

Returns the green value of c as an integer from 0 to 255. Check for null or use ?? before passing a nullable color.

Example

script "Green Channel"
data chart = subscribe(data.ohlcv)

on chart.update {
  let shade = chart.close >= chart.open ? color.green : color.red
  let green = color.g(shade)
}

color.b

color.b(c: color) -> int

Returns the blue channel from a color.

Returns the blue value of c as an integer from 0 to 255. Check for null or use ?? before passing a nullable color.

Example

script "Blue Channel"
data chart = subscribe(data.ohlcv)

on chart.update {
  let shade = chart.close >= chart.open ? color.blue : color.gray
  let blue = color.b(shade)
}

color.a

color.a(c: color) -> int

Returns the alpha channel from a color.

c must be a non-null color. The result is the non-null alpha channel as an integer in the 0..=255 range. Six-digit hex colors have alpha 255; eight-digit hex colors carry their explicit alpha value.

Example

script "Alpha Channel"
data chart = subscribe(data.ohlcv)

on chart.update {
  let faded = color.withAlpha(color.blue, 96)
  let alpha = color.a(faded)
}

color.lighten

color.lighten(c: color, percent: float) -> color

Lightens a color by mixing it toward white.

c is the starting color. percent sets how much to mix it toward white. The result is a non-null color with valid color-channel values.

Check for null or use ?? before passing nullable inputs.

Example

script "Lighten Color"
data chart = subscribe(data.ohlcv)
plot closeLine = plot.line(title: "Close")

on chart.update {
  let shade = color.lighten(color.blue, chart.close >= chart.open ? 20.0 : 0.0)
  closeLine.plot(chart.close, color: shade)
}
0
20
40
60
80
100

color.darken

color.darken(c: color, percent: float) -> color

Darkens a color by mixing it toward black.

c is the starting color. percent sets how much to mix it toward black. The result is a non-null color with valid color-channel values.

Check for null or use ?? before passing nullable inputs.

Example

script "Darken Color"
data chart = subscribe(data.ohlcv)
plot closeLine = plot.line(title: "Close")

on chart.update {
  let shade = color.darken(color.orange, chart.close < chart.open ? 20.0 : 0.0)
  closeLine.plot(chart.close, color: shade)
}
0
20
40
60
80
100

color.gradient

color.gradient(value: float, bottom: float, top: float, start: color, end: color) -> color

Blends between two colors based on a number.

value chooses a position between bottom and top. Values are clamped to that range without an error.

Returns start below the range or when bottom == top, and end above the range. Between the bounds, red, green, blue, and opacity change linearly. The result uses valid color-channel values.

Check for null or use ?? before passing nullable numbers or colors.

Example

script "Gradient Color"
data chart = subscribe(data.ohlcv)
plot momentum = plot.line(title: "Momentum")

on chart.update {
  let score = ta.roc(chart.close, 10) ?? 0.0
  let shade = color.gradient(score, -5.0, 5.0, color.red, color.green)
  momentum.plot(score, color: shade)
}

color.scale

color.scale(at: float[], colors: color[], space: ColorSpace = 2, easing: Easing = 1) -> ColorScale

Creates a color scale from a list of positions and colors.

Define the scale during setup, then read colors with .sample.

  • at lists positions in ascending order. colors lists the matching colors. Both setup arrays need the same length and at least two entries.
  • space chooses colorspace.rgb or colorspace.hsl, defaulting to HSL.
  • easing chooses how colors change between positions: easing.linear, easing.smoothstep, or easing.smootherstep. The default is linear.

Positions must be finite and cannot descend; invalid lists are rejected before the script runs. Equal adjacent positions create a sharp color change: the earlier color applies at that position, and the later color applies beyond it. Opacity always changes linearly.

The scale cannot be saved in state or passed to other calls. Use its .sample method to read it.

Example

script "Color Scale"
setup heat = color.scale(
  at:     [-1.0, 0.0, 1.0],
  colors: [color.red, color.gray, color.green],
  easing: easing.smoothstep,
)

data chart = subscribe(data.ohlcv)
plot out = plot.line(title: "out")

on chart.update {
  out.plot(chart.close, color: heat.sample(ta.roc(chart.close, 10) ?? 0.0))
}

Accepted values

RGB

Midpoint stays muddy olive because the channels blend directly.

HSL

Midpoint passes through bright yellow because hue rotates through the shortest path.

Linear

Color changes at a constant rate across the bar.

Smoothstep

The ends ease in and out, so the middle transitions faster.

Smootherstep

The same shape, but with even softer acceleration at both ends.

colorscale.sample

colorscale.sample(t: float) -> color

Reads a color from a scale at a position.

t chooses the position. Values outside the scale are clamped: below it returns the first color, above it returns the last. Null or NaN also returns the first color without an error.

Between positions, the scale's easing and color space determine the blend. HSL takes the shortest path around the color wheel. A gray endpoint uses the other endpoint's hue. Opacity changes linearly in every color space.

Example

script "Sample Color Scale"
setup heat = color.scale(
  at:     [-1.0, 0.0, 1.0],
  colors: [color.red, color.gray, color.green],
)

data chart = subscribe(data.ohlcv)
plot momentum = plot.line(title: "Momentum")

on chart.update {
  let value = ta.roc(chart.close, 10) ?? 0.0
  momentum.plot(value, color: heat.sample(value))
}

colorspace.rgb

colorspace.rgb: ColorSpace = 1

RGB color-scale interpolation by channel.

colorspace.hsl

colorspace.hsl: ColorSpace = 2

HSL color-scale interpolation with shortest-path hue.

easing.linear

easing.linear: Easing = 1

Linear segment easing, leaving the local position unchanged.

easing.smoothstep

easing.smoothstep: Easing = 2

Smoothstep segment easing with tt(3-2t).

easing.smootherstep

easing.smootherstep: Easing = 3

Smootherstep segment easing with ttt*(t*(6t-15)+10).

color.up

color.up: color = #00ff00

Bullish green (#00ff00).

color.green

color.green: color = #00ff00

Green (#00ff00).

color.down

color.down: color = #e81f59

Bearish red (#e81f59).

color.red

color.red: color = #e81f59

Red (#e81f59).

color.maroon

color.maroon: color = #800000

Maroon (#800000).

color.brown

color.brown: color = #a52a2a

Brown (#a52a2a).

color.orange

color.orange: color = #ffa500

Orange (#ffa500).

color.amber

color.amber: color = #f59e0b

Amber (#f59e0b).

color.yellow

color.yellow: color = #ffff00

Yellow (#ffff00).

color.olive

color.olive: color = #808000

Olive (#808000).

color.emerald

color.emerald: color = #16c784

Emerald (#16c784).

color.teal

color.teal: color = #008080

Teal (#008080).

color.cyan

color.cyan: color = #00eeff

Cyan (#00eeff).

color.lightskyblue

color.lightskyblue: color = #87cefa

Light sky blue (#87cefa).

color.blue

color.blue: color = #466be5

Blue (#466be5).

color.indigo

color.indigo: color = #2962ff

Indigo (#2962ff).

color.navy

color.navy: color = #000080

Navy (#000080).

color.purple

color.purple: color = #800080

Purple (#800080).

color.magenta

color.magenta: color = #ff00ff

Magenta (#ff00ff).

color.pink

color.pink: color = #ffc0cb

Pink (#ffc0cb).

color.white

color.white: color = #ffffff

White (#ffffff).

color.silver

color.silver: color = #9e9e9e

Silver (#9e9e9e).

color.gray

color.gray: color = #808080

Gray (#808080).

color.black

color.black: color = #000000

Black (#000000).

color.transparent

color.transparent: color = #00000000

Fully transparent black (#00000000).

On this page