Skip to main content
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);
  • 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. A signal built on the close of a forming bar can switch on and off as the price moves; guard it with barstate.isconfirmed:

calc_on_every_tick

The argument of indicator() and strategy() decides whether the forming bar runs at all before it closes. 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.