Sidechair

line.set_color()

Browse the reference

Recolors a whole line, or hides it with na.

Try it in the editor

The new color applies along the full length, extensions included. color.new(c, transparency) gives a faded line, and na keeps the object but draws nothing.

Because line.all reaches every line, one loop can restyle lines created on earlier bars.

Syntax

Pine Script
line.set_color(id: series line, color: series color) -> void
line.set_color(color: series color) -> void

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line to recolor. na is accepted and ignored.
colorseries colorrequiredNew line color. color.new(c, 70) gives a faded line; na hides it while the object stays on the chart.

Returns

Nothing.

Example

Pine ScriptFade each line with its ageOpen in editor
//@version=6
indicator("line.set_color: fade with age", overlay = true)
if bar_index % 20 == 0
    line.new(bar_index, low, bar_index + 15, low, color = color.blue, width = 2)
for ln in line.all
    line.set_color(ln, color.new(color.blue, math.min(90, bar_index - line.get_x1(ln))))

See also

Runs on Sidechair