> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to tell a forming bar from one that has closed

> Reading barstate.isconfirmed and barstate.isrealtime to separate a bar that is still updating from a closed one, and the flags that mark the end of the chart.

Read `barstate.isconfirmed`: it is true on historical bars (all but the last while the market is open) and, on the bar still forming, false until the bar closes. Each flag
is a `bool` series, so it answers for the bar the script is on.

```lipi wrap theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Bar states", overlay=true)
plot(close, title="Close", color=barstate.isconfirmed ? color.gray : color.orange)
bgcolor(barstate.isrealtime and not barstate.isconfirmed ? color.new(color.orange, 0.15) : na, title="Forming bar")
plotshape(barstate.islast, title="Last bar", shape=shape.circle, location=location.abovebar, color=color.blue, size=size.tiny)
```

## The seven flags

| Flag | True when |
| - | - |
| `barstate.isconfirmed` | the bar has closed (true on history, except the last bar while the market is open) |
| `barstate.isrealtime` | the bar is a live bar: true on every run of it, including the run when it closes, so `not barstate.isrealtime` is not the same as `barstate.isconfirmed` |
| `barstate.ishistory` | the bar is a historical bar |
| `barstate.isnew` | the first run of a bar; true on every historical bar |
| `barstate.isfirst` | the bar is the first bar of the chart |
| `barstate.islast` | the bar is the last bar of the chart |
| `barstate.islastconfirmedhistory` | the last loaded bar, when the market is closed; never true while the market is open |

`barstate.islast` and `barstate.islastconfirmedhistory` are separate flags; do not use one expecting the other. On a live chart
`islast` is true on the forming bar, so a script that draws on it runs again on every tick. With `calc_on_every_tick=false` the forming bar does not run until it closes (see [Recalculation and confirmation](https://gocharting.com/docs/scripting/evaluation/recalculation.md)); an `intra` variable keeps a value across the runs of one forming bar (see [Values that persist across bars](https://gocharting.com/docs/scripting/evaluation/persistence.md)).

## The mistake to avoid

> [!WARNING]
>
> Using the name `barstate.isnewbar`, which other languages have. The compiler says: Namespace `barstate` has no variable `isnewbar`. Did you mean `isnew`?
>
> ```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
> //@lipi=2
> indicator("New bar", overlay=true)
> bgcolor(barstate.isnewbar ? color.new(color.blue, 0.2) : na)
> ```

See [Recalculation and confirmation](https://gocharting.com/docs/scripting/evaluation/recalculation.md) and
[How to avoid a result that changes after the bar closes](https://gocharting.com/docs/scripting/how-to/avoid-a-result-that-changes-after-the-bar-closes.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.