Skip to content

close - PineScript Variable

close reports the last traded price of the active bar. While the bar is open, the value updates tick by tick; after the bar completes it becomes the final close.

  • Access historical closes with the history operator: close[1], close[2], etc.
  • On some synthetic chart types (e.g., Renko or Heikin Ashi) the value is derived from transformed data rather than raw trade prices.
  • When working on security requests, close reflects the requested symbol/timeframe context, not the main chart.
//@version=5
indicator("Close vs moving average", overlay=false)
length = input.int(50, "SMA length", minval=1)
sma = ta.sma(close, length)
plot(close, "Close", color=color.new(color.blue, 0))
plot(sma, "SMA", color=color.orange)
bgcolor(close > sma ? color.new(color.green, 88) : color.new(color.red, 88),
title="Close above/below SMA")