Appearance
Are you an LLM? You can read better optimized documentation at /reference/core/bar.md for this page in Markdown format
Bar
Kind: module
Namespace: bar
Provides functions for accessing the current bar state and detecting time-based boundaries.
bar.index()
Kind: func
Returns the index of the current bar.
Syntax
bar.index() → intReturns
Zero-based index of the current bar. First bar is 0.
Example
javascript
function onTick() {
// plot bar index as a rising line
spline(bar.index(), {title: "Bar #"});
}bar.isNew()
Kind: func
Checks if this is the first tick of a new bar.
Syntax
bar.isNew() → boolReturns
true on the first tick of a new bar (including all historical bars), false on subsequent real-time updates to the same bar.
bar.isConfirmed()
Kind: func
Checks if the current bar is confirmed (closed).
Syntax
bar.isConfirmed() → boolReturns
true if the bar is confirmed and will not change, false if the bar is still updating.
bar.isHistory()
Kind: func
Checks if the current bar is historical data.
Syntax
bar.isHistory() → boolReturns
true if processing historical data, false if processing realtime data.
Example
javascript
function onTick() {
const sma = ta.sma(close, 20);
// different colors for history vs realtime
const lineColor = bar.isHistory() ? color.GRAY : color.BLUE;
spline(sma, {title: "SMA", color: lineColor});
}bar.isNewDay()
Kind: func
Checks if this bar starts a new day.
Syntax
bar.isNewDay() → boolReturns
true if the current bar is the first bar of a new day, false otherwise.
bar.isNewWeek()
Kind: func
Checks if this bar starts a new week.
Syntax
bar.isNewWeek() → boolReturns
true if the current bar is the first bar of a new week, false otherwise.
bar.isNewMonth()
Kind: func
Checks if this bar starts a new month.
Syntax
bar.isNewMonth() → boolReturns
true if the current bar is the first bar of a new month, false otherwise.