Bar colouring and background
Four functions colour the chart itself rather than adding a line to it. Two of them recolour what is already there. Two of them draw candles or bars from series you supply.
All four are chart-output functions, so all four must be called at the top level of the script. A condition goes in the colour argument, not around the call.
Recolouring the bars
barcolor(series color color, const string title, input int offset) → voidbarcolor colours the price bars. It draws no value of its own: it changes the colour of bars that are already on the chart.
| Parameter | Type | Required | Notes |
|---|---|---|---|
color | series color | no | Series-form, so it may differ on every bar. |
title | const string | no | Const-form, so it cannot be built from series data. |
offset | input int | no | Input-form, so it cannot change from bar to bar. |
Shading the background
bgcolor(series color color, const string title, input int offset, const bool force_overlay) → voidbgcolor colours the background. Like barcolor it draws no value of its own.
| Parameter | Type | Required | Notes |
|---|---|---|---|
color | series color | no | Series-form, so it may differ on every bar. |
title | const string | no | Const-form, so it cannot be built from series data. |
offset | input int | no | Input-form, so it cannot change from bar to bar. |
force_overlay | const bool | no | Sets this drawing’s overlay, separately from the script-wide setting. |
bgcolor takes a force_overlay argument and barcolor does not.
indicator("Bar and background colour")
plot(close, title = "Close")
barcolor(color.orange, title = "Bars")
bgcolor(color.new(color.blue, 0.1), title = "Background")To shade only some bars, vary the colour rather than the call. The colour parameter is series-form, so it can differ from bar to bar; the call cannot be moved inside a branch.
Drawing your own candles
plotcandle(series float open, series float high, series float low, series float close, const string title, series color color, series color wickcolor, series color bordercolor, const bool force_overlay) → voidplotcandle needs four series: an open, a high, a low and a close. All four are required, and they are the first four arguments in that order.
| Parameter | Type | Required | Notes |
|---|---|---|---|
open | series float | yes | |
high | series float | yes | |
low | series float | yes | |
close | series float | yes | |
title | const string | no | Const-form, so it cannot be built from series data. |
color | series color | no | The body. |
wickcolor | series color | no | The wick. |
bordercolor | series color | no | The border. |
force_overlay | const bool | no | Sets this drawing’s overlay, separately from the script-wide setting. |
The body, the wick and the border take separate colours, and each of the three is series-form, so each can change from bar to bar.
indicator("Recoloured candles")
plotcandle(open, high, low, close, title = "Candles", color = color.new(color.blue, 0.8), wickcolor = color.gray, bordercolor = color.blue)Drawing your own bars
plotbar(series float open, series float high, series float low, series float close, const string title, series color color, const bool force_overlay) → voidplotbar takes the same four required series and one colour. There is no separate wick or border colour.
| Parameter | Type | Required | Notes |
|---|---|---|---|
open | series float | yes | |
high | series float | yes | |
low | series float | yes | |
close | series float | yes | |
title | const string | no | Const-form, so it cannot be built from series data. |
color | series color | no | The whole bar. |
force_overlay | const bool | no | Sets this drawing’s overlay, separately from the script-wide setting. |
Neither plotcandle nor plotbar has an offset parameter at all. Where an offset does exist on an output function it is input-form, so it never changes from bar to bar.
Reach for plotcandle unless you want a bar rather than a candle.