Sidechair

color.from_gradient()

Browse the reference

Returns a color blended between two colors according to where a value falls between two limits.

Try it in the editor

color.from_gradient maps value onto a range. At bottom_value the result is bottom_color, at top_value it is top_color, and in between each channel is interpolated in a straight line.

A value outside the range gets the nearest end color. Transparency is blended along with red, green and blue.

Syntax

Pine Script
color.from_gradient(value: series int/float, bottom_value: series int/float, top_value: series int/float, bottom_color: series color, top_color: series color) -> series color

Arguments

NameTypeDefaultDescription
valueseries int/floatrequiredThe number to position in the range.
bottom_valueseries int/floatrequiredThe value that gives bottom_color.
top_valueseries int/floatrequiredThe value that gives top_color.
bottom_colorseries colorrequiredColor shown when the value sits at bottom_value or below it.
top_colorseries colorrequiredColor shown when the value sits at top_value or above it.

Returns

series color: the blended color; na if value, a limit or a color is na.

Remarks

  • The two limits can be series, which lets a gradient follow a moving range such as ta.lowest and ta.highest.

Example

Pine ScriptGradient columns by RSIOpen in editor
//@version=6
indicator("RSI gradient")
r = ta.rsi(close, 14)
col = color.from_gradient(r, 30, 70, color.red, color.green)
plot(r, "RSI", color = col, style = plot.style_columns)
hline(50)

See also

Runs on Sidechair