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
Callinput.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.
At a Glance
Section titled “At a Glance”| Difficulty | Beginner |
| Time to implement | 5-10 min |
| Category | Inputs |
Quick Actions
Section titled “Quick Actions”Quick Start
Section titled “Quick Start”//@version=5indicator("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)Why It Matters
Section titled “Why It Matters”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.
What You’ll Learn
Section titled “What You’ll Learn”- 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.
Quick Reference
Section titled “Quick Reference”| Call | Purpose |
|---|---|
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. |
Implementation Blueprint
Section titled “Implementation Blueprint”-
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") -
Decorate the UI
Usetooltip,inline, andgroupto 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") -
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)
Example Playbook
Section titled “Example Playbook”//@version=5indicator("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)- 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.
Pro Tips & Pitfalls
Section titled “Pro Tips & Pitfalls”- 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.
Troubleshooting & FAQ
Section titled “Troubleshooting & FAQ”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.
Can I sync colour inputs across scripts?
Section titled “Can I sync colour inputs across scripts?”Not automatically. Provide consistent naming and default palettes so users can quickly mirror selections between indicators.
Key Takeaways
Section titled “Key Takeaways”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
groupandinlineto 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.
Keep Going
Section titled “Keep Going”- Open AI Editor to apply the pattern with guided assistance
- Browse Strategy Examples for ready-to-run templates
- Connect to Live Trading when you are ready to automate
Adapted from tradingcode.net, optimised for Algo Trade Analytics users.