Price series
20 entries. What each one takes, what it returns, and a working example.
barstate.islast / isconfirmed / isfirst / ishistory / isrealtime / isnew
Bar-state flags (return 1/0): barstate.islast (is this the last bar), isconfirmed (has the bar closed/confirmed — always 1 in backtest), isfirst (is this the first bar), ishistory (is this a closed historical bar — always 1 in backtest), isrealtime (is this a forming real-time bar — always 0 in backtest), isnew (is this a genuine new bar, as opposed to a tick-update of the same bar — always 1 in backtest). camelCase spellings are also valid (isLast/isConfirmed/isFirst/isHistory/isRealtime/isNew).
A set of bar-state flags accessed with a dot: barstate.islast, isconfirmed, isfirst, ishistory, isrealtime, isnew. Each returns 1 (true) / 0 (false) in a condition.
Note
islast = is this the last bar. isconfirmed = has the bar closed/confirmed (always 1 in backtest; the forming last bar is 0 live). isfirst = is this the first bar. ishistory = is this a closed historical bar (always 1 in backtest). isrealtime = is this a forming real-time bar (always 0 in backtest). isnew = is this a genuine new bar, as opposed to a price-update (tick-recompute) of the same bar (always 1 in backtest; live it's 0 when the same bar recomputes, 1 when a new bar arrives). Each member's camelCase spelling is also valid (isLast, isConfirmed, isFirst, isHistory, isRealtime, isNew).
if barstate.islast { label(close, "Last price: " + str.tostring(close), barIndex) }
Draws a price label only on the last bar (typical for live tracking).
if barstate.isnew { alert("New bar arrived", alert.freq_once_per_bar) }
Only fires the alert when a genuinely new bar arrives; does not repeat on intrabar price updates of the same bar.
Close price series.
A series holding each bar's closing price.
Note
The most commonly used price source; the default input of most indicators (sma/ema/rsi...) is close.
When to use
The default source when an indicator or rule is price-based. Use hl2 for the bar-body midpoint, or hlc3/ohlc4 to smooth out noise.
plot(sma(close, 20))
The 20-bar moving average of the close as a line on the price panel.
plot(close > open ? 1 : 0)
1 when the bar is green (close above open), otherwise 0.
The day-of-month of the current bar (1-31), in the exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error.
plot(dayofmonth)
Plots each bar's day-of-month value (1-31).
The day of week of the current bar (Sunday=1.. Saturday=7).
The day of week of the current bar (Sunday=1.. Saturday=7), in the exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error.
Limits
Named constants like `dayofweek.monday` can be used instead of the raw numbers.
plot(dayofweek == dayofweek.monday ? 1 : 0, "is it Monday")
Plots 1 on Monday bars, 0 on other days.
High price series.
A series holding each bar's highest price.
Note
It is the top of the wick; used in resistance, breakout and highest computations.
When to use
In resistance/breakout rules: close > highest(high, 20). In wick range and volatility measurement.
plot(highest(high, 20))
A line tracking the highest peak of the last 20 bars (upper envelope).
plot(high - low)
The bar range: the distance between the high and the low.
Median price: (high + low) / 2.
The median price series: (high + low) / 2.
Note
If a bar's high or low is na, that bar's hl2 is na. It is a body-midpoint source, less noisy than close.
When to use
When you want average/channel indicators anchored to the mid-price. When you need a more balanced source than close.
plot(sma(hl2, 20))
The 20-bar average of the mid-price; a smoother line than using close.
Typical price: (high + low + close) / 3.
The typical price series: (high + low + close) / 3.
Note
A balanced price source that also accounts for the close; the classic input for volume-weighted indicators.
When to use
In typical-price based indicators (e.g. a volume-weighted average) and when you want to weigh the close together with the wicks.
plot(sma(hlc3, 20))
The 20-bar average of the typical price.
The hour of the current bar (0-23), in the symbol's exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error.
plot(hour == 10 ? 1 : 0, "is it 10:00")
Plots 1 when the bar's hour is exactly 10, 0 otherwise.
Low price series.
A series holding each bar's lowest price.
Note
It is the bottom of the wick; used in support, downside breaks and lowest computations.
When to use
In support/downside rules: close < lowest(low, 20). When placing a stop level or hunting for lows.
plot(lowest(low, 20))
A line tracking the lowest trough of the last 20 bars (lower envelope).
plotshape(low == lowest(low, 20), style="triangleup", location="belowbar")
An up-triangle below the bar on 20-bar lowest bars.
The minute of the current bar (0-59), in the exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error.
plot(minute)
Plots each bar's minute value (0-59).
The month of the current bar (1-12). Use month != month[1] to catch a month change.
The month of the current bar (1-12), in the exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error. Use `month != month[1]` to catch a month change.
plot(month != month[1] ? 1 : 0, "has the month changed")
Plots 1 on the first bar of a new month, 0 otherwise.
Average price: (open + high + low + close) / 4.
The average price series: (open + high + low + close) / 4.
Note
The smoothest source, weighting all four prices equally; it reduces noise but reacts a touch slower.
When to use
When you want the price source as smooth as possible and do not want individual wick tips to disturb the rule.
plot(ema(ohlc4, 20))
The 20-bar exponential average of the average price; one of the smoothest lines.
Open price series.
A series holding each bar's opening price.
Note
It is the start of the candle body; compared with close it gives the bar's direction (up/down).
When to use
When computing body direction or size (close - open). In gap analysis, to compare the open against the previous close.
plot(close - open)
Signed body size: positive for an up bar, negative for a down bar.
plot(open - prev(close, 1))
The opening gap: the open relative to the previous close.
The second of the current bar (0-59), in the exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error. On charts with a minute/hour/day bar duration this is always 0 (bars start on the minute).
plot(second)
Varies 0-59 on a 1-second chart; always 0 on a 1-minute+ chart.
session.ismarket / ispremarket / ispostmarket
Session state (Phase 1 — regular-session constant): session.ismarket (always true), ispremarket/ispostmarket (always false). Note: session.regular/extended are SEPARATE constants (for the session() function).
Session state variables: session.ismarket, ispremarket, ispostmarket.
Note
Phase 1: regular-session default is constant — ismarket always true, ispremarket/ispostmarket always false. session.regular/extended are SEPARATE constants (for the session() function argument).
bgcolor(session.ismarket ? "#26a69a15" : na)
Tints the chart background light green during the regular session and leaves out-of-session bars unpainted.
syminfo.ticker / mintick / timezone / pointvalue
Symbol information (dot access). Fields backed by real data: syminfo.ticker, syminfo.mintick, syminfo.timezone, syminfo.pointvalue. currency / basecurrency / description / prefix / root / type / session cannot be resolved: an explicit error is raised instead of a silent empty value.
plot(strLength(syminfo.ticker))
Plots how many characters the symbol name has; symbol info is text and cannot be plotted directly, so this example turns it into a number.
timeframe.period / multiplier / isdaily / isweekly / ismonthly / isintraday / isminutes / isseconds
Chart timeframe metadata: timeframe.period (TF text "5"/"60"/"D"/"W"/"M"), multiplier (5m→5, hourly→60, D/W/M→1), isdaily/isweekly/ismonthly (true/false), isintraday, isminutes/isseconds. All derived from the bar time-delta.
Chart timeframe metadata variables (dot access): period, multiplier, isdaily, isweekly, ismonthly, isintraday, isminutes, isseconds.
Note
period = TF text. multiplier = numeric (5m→5, hourly→60, daily/weekly/monthly→1). isdaily/isweekly/ismonthly = whether that TF (true/false). isintraday = intraday. isminutes/isseconds = minute/second based. All derived from the bar time-delta.
plot(timeframe.isintraday ? 1 : 0, "Intraday")
Plots 1 when the chart is on an intraday timeframe and 0 on daily or higher; it lets the same code behave differently across timeframes.
Volume series.
A series holding each bar's traded volume.
Note
On some data sources volume can be 0 or missing (na); it is wise to guard volume-based rules with nz.
When to use
For volume confirmation, a volume average (sma(volume,20)) and cumulative volume (cum(volume)). When confirming a price breakout with volume.
plot(sma(volume, 20))
The 20-bar average volume; a baseline to compare volume spikes against.
plotshape(volume > sma(volume, 20) * 2, style="circle", location="bottom")
A circle in the bottom band on bars where volume exceeds twice its average.
The week-of-year of the current bar (1-53), counted from the start of the calendar year.
The week-of-year of the current bar (1-53).
Note
The week is counted in 7-day blocks starting from the calendar year's January 1st — this is NOT the ISO-8601 week definition (it never jumps year, so it always stays consistent with `year`). Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error.
plot(weekofyear)
Plots each bar's week-of-year (1-53).
The year of the current bar (e.g. 2024), in the exchange timezone.
Note
Only works for supported symbols/exchange timezones: crypto (UTC), VİOP (Istanbul, no DST), a handful of fixed US/EU/Tokyo zones (including DST rules). For an unsupported symbol/zone, or a year outside the DST rule's range (before 2007 for US, before 1996 for EU), reading the variable raises a clear error.
plot(year)
Plots each bar's year (e.g. 2024).
Bar index (starts at 0, increments by 1 each bar). the snake_case spelling `bar_index` is also valid.
The bar-index series: starts at 0, increments by 1 each bar.
Note
the snake_case spelling `bar_index` refers to the same series — both are valid.
When to use
When writing a condition against a specific bar (e.g. the first bar), or anchoring drawing objects to a bar offset.
if barIndex == 0 { plot(close, "first-bar") }
Plots the close only on the chart's very first bar; nothing is drawn on later bars.
Index of the last bar (bar-invariant constant series: same on every bar, including historical ones). the snake_case spelling `last_bar_index` is also valid.
The index of the last bar — a bar-invariant constant series: it carries the same value on every bar, including historical ones.
Note
the snake_case spelling `last_bar_index` refers to the same series — both are valid.
When to use
When writing the "I am on the last bar right now" condition (`barIndex == lastBarIndex`).
if barIndex == lastBarIndex { label(close, "last bar", barIndex) }
Places a label reading "last bar" on the chart's final bar; no label appears on past bars.
Time of the last bar (Unix milliseconds, bar-invariant constant series). the snake_case spelling `last_bar_time` is also valid.
The time of the last bar (Unix milliseconds) — a bar-invariant constant series.
Note
the snake_case spelling `last_bar_time` refers to the same series — both are valid.
When to use
When you need to read the last bar's timestamp (e.g. for a counter/countdown).
plot(lastBarTime)
Plots the timestamp of the last bar; because it is drawn as a number you see a flat line, hover it to read the value.
Bar time (Unix milliseconds). Not to be confused with the `time_close(tf)` function — this is a plain series (no parentheses).
The bar-time series (Unix milliseconds).
Note
This is a plain series (no parentheses) — do not confuse it with the `time_close(timeframe)` function, which is a separate call.
When to use
When writing a condition based on bar time, or building custom date/time logic.
plot(time)
Plots each bar's timestamp; it gives a steadily rising line, useful for spotting gaps between bars.