Skip to content

hline() - Pine Script Function

hline() draws a horizontal line at a constant price level. The function returns a handle you can reuse to change color, fill between lines, or delete it later.

hline(price, title, color, linestyle, linewidth, editable, display) → hline
NameTypeDescription
priceconst floatPrice level for the line. Required.
titleconst stringLabel shown in the Style settings.
colorconst colorLine color (defaults to chart theme).
linestyleconst line.styleLine style (solid, dotted, dashed).
linewidthconst intLine thickness.
editableconst boolAllow users to adjust style in the settings panel. Defaults to true.
displayconst stringDisplay mode (see display.*).

An hline object that can be passed to functions like fill() or deleted later.

//@version=5
indicator("hline example", overlay=true)
mid = plot(ta.sma(close, 50), "Mid", color=color.orange)
upperLevel = hline(ta.sma(close, 50) + ta.atr(14), "Upper", color=color.green)
lowerLevel = hline(ta.sma(close, 50) - ta.atr(14), "Lower", color=color.red)
fill(upperLevel, lowerLevel, color.new(color.teal, 90))
plot(close, "Close", color=color.blue)