Skip to content

How to make a colour input in TradingView's Pine Script?

How to make a colour input in TradingView’s Pine Script?

Section titled “How to make a colour input in TradingView’s Pine Script?”

TL;DR
Call input.color(defval, title=...) to add a colour picker to the settings panel, then reuse the returned value anywhere you would normally pass a colour constant.

DifficultyBeginner
Time to implement5-10 min
CategoryInputs
//@version=5
indicator("Custom colour inputs", overlay=true)
plotColour = input.color(color.teal, "EMA colour")
fillColour = input.color(color.new(color.teal, 80), "Fill transparency")
backgroundOn = input.bool(true, "Highlight trend?", inline="bg")
backgroundCo = input.color(color.new(color.green, 90), " ", inline="bg")
emaLine = ta.ema(close, 34)
plot(emaLine, color=plotColour, linewidth=2)
if backgroundOn
bgcolor(backgroundCo)
Tip. Use `inline=` to cluster related inputs (like a bool toggle plus colour picker) on a single row, keeping the Inputs panel tidy.

Colour inputs hand control back to the trader: they can match brand palettes, adjust transparency for dark/light themes, or coordinate multiple indicators without touching code. When scripts ship pre-configured colours, they rarely fit every chart—input.color() keeps the experience versatile.

  • Define simple colour pickers and capture their values in variables.
  • Provide transparent defaults with color.new() so overlays stay readable.
  • Group related inputs (labels, inline rows, tooltips) for better UX.
  • Apply colour inputs to plots, backgrounds, fills, and label styling.
CallPurpose
input.color(defval, title=?, tooltip=?, inline=?, group=?, confirm=?)Registers a colour picker in the settings UI.
color.new(base, transparency)Sets default opacity for the colour input value.
plot(series, color=...)Plots lines using the selected colour.
bgcolor(color)Shades the chart background with the chosen colour.
label.new(..., bgcolor=?, textcolor=?)Styles labels using user-selected colours.
  1. Capture the colour input
    Store the return value in a variable and give the input a descriptive title.

    signalColour = input.color(color.new(color.purple, 60), "Signal highlight")
  2. Decorate the UI
    Use tooltip, inline, and group to organise settings, especially when offering multiple palettes.

    group = "Alert styling"
    alertTextColour = input.color(color.white, "Text", group=group, inline="alert")
    alertBgColour = input.color(color.new(color.red, 70), "Background", group=group, inline="alert")
  3. Apply everywhere you need colour
    Pass the input variable to plots, fills, labels, or themes without rewriting logic.

    label.new(bar_index, high, "Alert!", textcolor=alertTextColour, bgcolor=alertBgColour)
//@version=5
indicator("Palette-driven moving averages", overlay=true, max_labels_count=100)
maGroup = "Moving averages"
fillGroup = "Fill styling"
fastColour = input.color(color.new(color.green, 0), "Fast MA", group=maGroup, inline="ma")
slowColour = input.color(color.new(color.orange, 0), "Slow MA", group=maGroup, inline="ma")
fillBase = input.color(color.new(color.green, 85), "Fill base", group=fillGroup, tooltip="Applied when fast MA is above slow MA")
fillAlt = input.color(color.new(color.red, 85), "Fill alt", group=fillGroup, tooltip="Applied when fast MA is below slow MA")
fastLen = input.int(21, "Fast length")
slowLen = input.int(55, "Slow length")
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
plotFast = plot(fast, "Fast", color=fastColour, linewidth=2)
plotSlow = plot(slow, "Slow", color=slowColour, linewidth=2)
fill(plotFast, plotSlow, color=fast > slow ? fillBase : fillAlt)
trendLabelColour = input.color(color.new(color.blue, 60), "Trend label", group=fillGroup)
trendTextColour = input.color(color.white, "Label text", group=fillGroup)
if barstate.islast
label.new(bar_index, fast,
text=fast > slow ? "Bullish trend" : "Bearish trend",
style=label.style_label_left,
textcolor=trendTextColour,
bgcolor=trendLabelColour)
Why this works.
  • Grouped inputs keep the configuration organised even with multiple colour pickers.
  • Transparent defaults look good on both light and dark themes while still allowing override.
  • The example touches plots, fills, and labels—showing colour inputs are reusable everywhere.
  • Inputs require constant arguments—no ternary expressions inside input.color. Decide defaults before the call.
  • Provide white/black text inputs alongside label background colours so users maintain readability.
  • For strategies, combine colour inputs with plot/alert styling so signals stay consistent with manual chart drawings.
  • When you have many colour options, add sections (group=) and use inline keys to prevent vertical sprawl.

My default transparency disappears when the user changes colour

Section titled “My default transparency disappears when the user changes colour”

Add a tooltip reminding users to adjust the transparency slider in the picker. Or expose a separate input.int for opacity and apply it via color.new(selectedColour, opacity).

Why does TradingView warn about “no output function”?

Section titled “Why does TradingView warn about “no output function”?”

Ensure you still plot or colour something (like in the example). Colour inputs alone do not count as outputs.

Not automatically. Provide consistent naming and default palettes so users can quickly mirror selections between indicators.

  • input.color() places a colour picker in settings; the returned value is a standard Pine colour you can use anywhere.
  • Organise multiple colour inputs with group and inline to keep the UI approachable.
  • Pair colour inputs with transparency via color.new() so overlays stay legible by default.
  • Applying the user-selected colour to plots, fills, labels, and backgrounds keeps the entire script customisable.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.