Skip to content

open - PineScript Variable

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.

  • 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 close to identify bar direction or to colour candles conditionally.
//@version=5
indicator("Open gap detector", overlay=true)
gapThreshold = input.float(0.5, "Gap percent", step=0.1)
gapUp = ta.change(open) / open[1] * 100 > gapThreshold
gapDown = 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↓")