How to let the chart user choose a colour
Call input.color once, at the top level, and pass what it gives you to the
drawing.
input.color(const color defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input colorindicator("Reader's colour", "usercol", true)
line_colour = input.color(color.blue, "Line colour")
plot(close, title = "Close", color = line_colour)The first argument is the colour the control starts at. The second is its label.
If you want one colour for rising and another for falling
Declare two controls and choose between them in the colour argument.
indicator("Direction colours", "dircol", true)
up = input.color(color.green, "Rising", group = "Appearance")
down = input.color(color.red, "Falling", group = "Appearance")
plot(close, title = "Close", color = close > close[1] ? up : down)What you get back
An input color, not a const color. The input form sits above const in
the ordering of forms, so the reader’s choice is accepted where a simple or
series colour is wanted, and refused where a const is required.
The failures to watch for
- An input argument cannot be
na. The interpreter rejects it. Give the control a real default colour. - The default is a
const color, so a named constant or a hex literal will do and a value read off a bar will not.
See Inputs and Colour and transparency.
Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.