open - PineScript Variable
Overview
Section titled “Overview”open captures the price at which the current bar began trading. The value is fixed for the entire bar and only updates when a new bar starts.
Remarks
Section titled “Remarks”- Access earlier opens with
open[1],open[2], etc., when comparing gaps or building range calculations. - On transformed chart types (e.g., Heikin Ashi), the open may be a synthetic value derived from previous bars.
- Combine with
closeto identify bar direction or to colour candles conditionally.
Example
Section titled “Example”//@version=5indicator("Open gap detector", overlay=true)
gapThreshold = input.float(0.5, "Gap percent", step=0.1)gapUp = ta.change(open) / open[1] * 100 > gapThresholdgapDown = ta.change(open) / open[1] * 100 < -gapThreshold
plotshape(gapUp, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), text="Gap↑")plotshape(gapDown, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), text="Gap↓")