> ## 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.

# Recalculation and confirmation

> How the script runs on every tick of the forming bar, what is reset between ticks, barstate.isconfirmed, and calc_on_every_tick.

On history each bar runs once, after it has closed. The newest bar of a live chart has not closed, so its price keeps changing and
the script runs again on every tick; the result for that bar can change until it closes. A closed bar is confirmed and never
recalculated.

## What a tick starts from

Before each run on the forming bar the chart restores the state of the last confirmed bar:

* series history (`x[1]`) and `talib` state have not advanced;
* `static` variables have the value committed at the last close (see [Values that persist across bars](https://gocharting.com/docs/scripting/evaluation/persistence.md));
* drawings are those of the last confirmed bar, so a label made on an earlier tick of this bar is gone;
* only `intra` variables keep what the previous tick left.

When the bar closes, the script runs once more with `barstate.isconfirmed` true and that result is committed.

## The barstate variables

All are `bool` series values.

| Variable | True when |
| - | - |
| `barstate.isconfirmed` | the bar has closed: every historical bar and the last run of a live bar. False on earlier ticks of a forming bar and on the last historical bar while the market is open |
| `barstate.isnew` | the first run of the bar (every historical bar) |
| `barstate.isrealtime`, `barstate.ishistory` | the bar is live (on every run of it, the closing run too), or was loaded as history |
| `barstate.islast`, `barstate.isfirst` | the newest bar, the first bar of the chart |
| `barstate.islastconfirmedhistory` | the last loaded bar, when the market is closed |

A signal built on the `close` of a forming bar can switch on and off as the price moves; guard it with `barstate.isconfirmed`:

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Confirmed up bar", overlay=true)
bool signal = close > open and barstate.isconfirmed
plotshape(signal, title="Up bar", shape=shape.triangleup, location=location.belowbar)
```

## calc\_on\_every\_tick

The argument of `indicator()` and `strategy()` decides whether the forming bar runs at all before it closes.

| Script | Default | `true` | `false` |
| - | - | - | - |
| `indicator()` | `true` | runs on every tick | runs only when the bar closes; nothing is shown for the forming bar until then |
| `strategy()` | `false` | runs on every tick | runs when the bar closes (and after an order fill when `calc_on_order_fills=true`) |

`calc_on_every_tick` does not change history: every closed bar runs once, plus a rerun after each fill in a strategy with `calc_on_order_fills=true`. `alert()` fires at most once per bar and only on live bars.


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