hl2 - PineScript Variable
Overview
Section titled “Overview”hl2 is a shorthand for (high + low) / 2. It provides the midpoint of the bar’s range and is often used as a smoother input compared to raw closes.
floatQualifier
Section titled “Qualifier”series
Remarks
Section titled “Remarks”- Unlike
close,hl2softens intrabar noise by averaging extremes. - Because it depends on
high/low,hl2updates intra-bar whenever a new extreme is made, then locks at bar close. - Works well as a source input to moving averages or oscillators when you want a blend of high/low information.
Example
Section titled “Example”//@version=5indicator("HL2 vs Close", overlay=false)
plot(close, "Close", color=color.blue)plot(hl2, "HL2 midpoint", color=color.orange)
spread = close - hl2plot(spread, "Close - HL2", color=color.new(color.purple, 0), display=display.none)