hline() - Pine Script Function
hline()
Section titled “hline()”Overview
Section titled “Overview”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.
Syntax
Section titled “Syntax”hline(price, title, color, linestyle, linewidth, editable, display) → hlineParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
price | const float | Price level for the line. Required. |
title | const string | Label shown in the Style settings. |
color | const color | Line color (defaults to chart theme). |
linestyle | const line.style | Line style (solid, dotted, dashed). |
linewidth | const int | Line thickness. |
editable | const bool | Allow users to adjust style in the settings panel. Defaults to true. |
display | const string | Display mode (see display.*). |
Returns
Section titled “Returns”An hline object that can be passed to functions like fill() or deleted later.
Examples
Section titled “Examples”//@version=5indicator("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)