Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

Language

Bar states

barstate.* tells the script where it is in the run: the first bar, the last, history or live, and whether the bar has closed.

View as MarkdownOpen in ClaudeOpen in ChatGPT

Because a script runs once per bar, it sometimes needs to know which bar it is on.

Variabletrue when
barstate.isfirstThe first bar of the run
barstate.islastThe last bar on the chart (the forming one, when live)
barstate.ishistoryA bar that had closed before the chart loaded
barstate.isrealtimeA bar forming while the chart is open
barstate.isnewThe first update of a new bar
barstate.isconfirmedThe bar has closed
barstate.islastconfirmedhistoryThe last closed bar before live bars began

The two you will use most#

Draw once, at the end. Wrap drawings and tables in if barstate.islast so they are made once rather than on every bar of history.

Signal only on closed bars. On the live bar, prices move until it closes. A condition can be true mid-bar and false at the close. Require barstate.isconfirmed for signals that must not disappear:

RunnableConfirmed crosses
1//@version=62indicator("Confirmed crosses", overlay = true)3f = ta.ema(close, 9)4s = ta.ema(close, 21)5plotshape(ta.crossover(f, s) and barstate.isconfirmed, "Confirmed", style = shape.triangleup, location = location.belowbar, color = color.teal)

On history every bar is confirmed, so this only changes behaviour live. See Repainting.

PreviousTime and sessionsNext Plotting

On this page

  • The two you will use most

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT