Fills and levels
A level is a horizontal line at a fixed price. A fill is the shading between two of them, or between two plots. Both are chart-output functions, so both must be called at the top level of the script, outside any branch, loop or function of your own.
Levels
hline(input float price, const string title, input color color, input int linewidth, input hlineStyle style) → series hline| Parameter | Type | Required | Notes |
|---|---|---|---|
price | input float | yes | The price the line sits at. |
title | const string | no | The name of the line. Const-form, so it cannot be built from series data. |
color | input color | no | Input-form, not series: a level’s colour is fixed for the run of the script. |
linewidth | input int | no | Input-form, so it is fixed for the run of the script. |
style | input hlineStyle | no | solid, dashed or dotted. |
A level’s price cannot change from bar to bar. The parameter is input-form, so the value is settled before the script runs and holds for every bar. A line that has to follow the data is a plot, not a level.
hline returns an hline value. Keep it in a variable and you can pass two of them to fill.
Fills
fill joins two plots, or two horizontal lines. It cannot join one of each. There are two forms and no mixed one.
fill(series hline h1, series hline h2, series color color, const string title, const bool fillgaps) → voidfill(series plot p1, series plot p2, const string title, series color color, const bool fillgaps) → voidRead those two lines together, because the difference between them is the thing that bites. The two forms take their remaining arguments in a different order. For horizontal lines the third argument is the colour. For plots the third argument is the title. Name the arguments and the difference stops mattering.
| Form | Third argument | Fourth argument |
|---|---|---|
| two horizontal lines | color | title |
| two plots | title | color |
In both forms the first two arguments are required and the rest are not. Both forms end with fillgaps, which is const-form and therefore fixed for the run of the script.
Filling between two levels
indicator("Band between two levels")
plot(close, title = "Close", color = color.gray)
upper = hline(70, title = "Upper", color = color.red, style = hlineStyle.dashed)
lower = hline(30, title = "Lower", color = color.green, style = hlineStyle.dashed)
fill(h1 = upper, h2 = lower, color = color.new(color.gray, 0.1), title = "Band")Filling between two plots
indicator("Range band")
top = plot(high, title = "High", color = color.new(color.blue, 0.8))
bottom = plot(low, title = "Low", color = color.new(color.blue, 0.8))
fill(p1 = top, p2 = bottom, title = "Range", color = color.new(color.blue, 0.15))A fill between two plots is the reason plot returns a value at all. Assign each plot to a variable at the top level, then pass the two variables.
Offsets in a plot fill
When you fill between two plots, the fill keeps an offset only if both plots carry the same one. If the two plots disagree, the fill uses none. Set the same offset on both plots, or set it on neither.