Can you please explain how to use barstate.islastconfirmedhistory
?
Can anyone create a sample program where the below built-in variable is used?
barstate.islastconfirmedhistory
It is used to figure out the last historical bar when you add your script to the chart.
The word "last historical" is very important here.
What that means is:
true
for the bar preciding the real-time barExample:
//@version=5
indicator(title="My Script", overlay=true)
if barstate.islastconfirmedhistory
label.new(x=bar_index, y=high, color=color.green, textcolor=color.white, text="Last\nhistorical\nbar")
If I add this to BTC (which is currently trading) and change my timeframe to 5 seconds (so new bars form quickly), you can actually see the point when I added this indicator to my chart.
If I add the same script to APPL, which is currently not trading, it will point to the last bar.