Why the live candle runs your code on every tick · Pine Script S2 EP 01 #shorts

History = one run per candle. Live = one run per tick, with a rollback before each. Here’s how Pine’s engine really works.

Before every tick on the live candle the script’s values are reset to the last committed state (rollback) — even `var` variables — and only the closing tick’s values are saved. A refresh turns the earlier live candles into history, so they then run once. Three flags: barstate.isrealtime (is this the live candle?) · barstate.isconfirmed (is this candle finished? true on all history + the closing tick) · barstate.islast (the chart’s last candle, live or not). Full script in the first comment.

Educational content about Pine Script coding. Not investment advice.

Your rules. Coded. · marketalgobot.com
https://marketalgobot.com

#pinescript #tradingview #coding #learntocode #marketalgobot