Black Friday 30% off Basic and ProBlack Friday −30%Ends in––d––h––m––sSee the deal

Colors and style

How to write colors, fills, baselines and colors that change candle by candle.

color

Python
color("#2962FF")      # hex
color("#2962FF", 50)  # with opacity, from 0 to 100
color("up", 30)       # theme color

The theme colors are up, down, line, buy, sell, neutral and text: they follow the light and dark theme until the user changes them. They exist only in plots; drawings use hex colors. A text instead of color(…) is an error.

One color per candle

Instead of a color you can write a list of named colors: (name, label, color). The function picks a name for each candle and returns a pair: the values and the names. The settings have one button per color, with its label.

A histogram with four colors
The MACD histogram with four colors: rising or falling, above or below zero.
Python
plot.series("hist", "Histogram", type="columns", color=[
    ("rising_above", "Rising above zero", color("#26A69A")),
    ("falling_above", "Falling above zero", color("#B2DFDB")),
    ("rising_below", "Rising below zero", color("#FFCDD2")),
    ("falling_below", "Falling below zero", color("#FF5252")),
])
# in the function:
return {"hist": (hist, colors)}

The name is in snake_case and is also the key of the saved color: you can change the label without losing the colors chosen by the user.

Fills and gradient

A fill is a dictionary: color and, if you want a gradient, "gradient": True with bottom_color. In plots it fades from the top to the bottom of the pane.

A gradient fill below an average
A fill from the average down to the bottom of the pane, with a gradient.
Python
plot.fill("glow", "Fill", "sma", "bottom", fill={
    "color": color("#7E57C2", 40),
    "gradient": True,
    "bottom_color": color("#7E57C2", 0),
})

Baseline

The "baseline" type colors above and below a level, like an oscillator’s zero: up and down are the lines, up_fill and down_fill the fills. You only write what changes.

Python
plot.series("momentum", "Momentum", type="baseline", baseline={
    "level": 0,
    "up": {"color": color("up"), "width": 2},
    "down": {"color": color("down"), "width": 2},
})

How style is written

Plots and drawings write their style the same way, with the names of their settings:

  • a simple field is an argument: type="line", extend_end=True;
  • a group is a dictionary: line={"color": color("#2962FF"), "width": 2};
  • names are in snake_case, and a missing field takes the default value.

A wrong name or value is a compile error, with the line: the message says what was expected.