How to tell a forming bar from one that has closed
Read barstate.isrealtime. It is true when the bar under evaluation is still
updating and false once that bar has closed.
indicator("Forming bar", "forming", true)
plot(close, title = "Close", color = barstate.isrealtime ? color.orange : color.gray)The flag is a series bool, so it answers for the bar the script is on, not for
the chart as a whole.
If you want the closed bars instead
barstate.ishistory is true on a historical bar. It is the flag to test when
your logic should run over settled bars and stay out of the way on the one that
is still moving.
If you want the end of the chart
Two flags mark single positions rather than ranges.
| Flag | Marks |
|---|---|
barstate.islast | the last bar of the chart |
barstate.islastconfirmedhistory | the last confirmed historical bar |
They are separate flags. Do not use one expecting the other.
The name you may be reaching for
barstate.isconfirmed does not exist in Lipi. Use barstate.isrealtime and read
it the other way round.
What this recipe does not tell you
It does not tell you how often a script is evaluated while a bar is still updating, what triggers each evaluation, or whether a script is evaluated again over bars it has already seen. Do not infer any of that from the flags. See Recalculation and confirmation.