hline(price, title?, color?, linestyle?, linewidth?, editable?, display?)
hline(70, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(30, "Oversold", color=color.lime, linestyle=hline.style_dashed)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)
| Parameter | Type | Default | Meaning |
|---|---|---|---|
price |
const float | required | The y-coordinate. hline(50) draws a horizontal line at 50. |
title |
const string | "" |
Dialog label. |
color |
const color | #2962FF |
Line colour. |
linestyle |
const | hline.style_solid |
.style_dashed, .style_dotted. |
linewidth |
const int | 1 |
1–4. |
editable |
const bool | true |
false hides the Style tab row. |
display |
const | display.all |
Combine display.* modes same as plot. |
Returning the handle
hline() returns a reference you can pass to fill():
upper = hline(70, "Upper", color=color.red)
lower = hline(30, "Lower", color=color.lime)
fill(upper, lower, color=color.new(color.gray, 92))
trackprice vs hline
hline(50)— a fixed y-coordinate for the whole chart.plot(ta.sma(close, 20), trackprice=true)— a dotted horizontal line at the plot's last value, moving every bar.
Use hline for constant levels, trackprice for last-value trackers.
When to prefer a drawing
line.new() is the right choice when the level moves (support/resistance built from pivots), when it should extend only part of the chart, or when it should be deletable:
var line lastSup = na
p = ta.pivotlow(5, 5)
if not na(p)
line.delete(lastSup)
lastSup := line.new(bar_index[5], p, bar_index + 50, p,
color=color.lime, extend=extend.right)
See also
- Plots —
trackprice - Lines and boxes
- Fills