CODESCRIPT

Price series

20 entries. What each one takes, what it returns, and a working example.

barstate.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).

CODESCRIPT
if barstate.islast {
  label(close, "Son fiyat: " + str.tostring(close), barIndex)
}

Draws a price label only on the last bar (typical for live tracking).

CODESCRIPT
if barstate.isnew {
  alert("Yeni bar geldi", 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

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.

CODESCRIPT
plot(sma(close, 20))

The 20-bar moving average of the close as a line on the price panel.

CODESCRIPT
plot(close > open ? 1 : 0)

1 when the bar is green (close above open), otherwise 0.

dayofmonth

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.

CODESCRIPT
plot(dayofmonth)

Plots each bar's day-of-month value (1-31).

dayofweek

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.

CODESCRIPT
plot(dayofweek == dayofweek.monday ? 1 : 0, "Pazartesi mi")

Plots 1 on Monday bars, 0 on other days.

high

A series holding each bar's highest price.

NOTE

It is the top of the wick; used in resistance, breakout and highest computations.

CODESCRIPT
plot(highest(high, 20))

A line tracking the highest peak of the last 20 bars (upper envelope).

CODESCRIPT
plot(high - low)

The bar range: the distance between the high and the low.

hl2

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.

CODESCRIPT
plot(sma(hl2, 20))

The 20-bar average of the mid-price; a smoother line than using close.

hlc3

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.

CODESCRIPT
plot(sma(hlc3, 20))

The 20-bar average of the typical price.

hour

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.

CODESCRIPT
plot(hour == 10 ? 1 : 0, "10:00 mu")

Plots 1 when the bar's hour is exactly 10, 0 otherwise.

low

A series holding each bar's lowest price.

NOTE

It is the bottom of the wick; used in support, downside breaks and lowest computations.

CODESCRIPT
plot(lowest(low, 20))

A line tracking the lowest trough of the last 20 bars (lower envelope).

CODESCRIPT
plotshape(low == lowest(low, 20), style="triangleup", location="belowbar")

An up-triangle below the bar on 20-bar lowest bars.

minute

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.

CODESCRIPT
plot(minute)

Plots each bar's minute value (0-59).

month

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.

CODESCRIPT
plot(month != month[1] ? 1 : 0, "Ay değişti mi")

Plots 1 on the first bar of a new month, 0 otherwise.

ohlc4

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.

CODESCRIPT
plot(ema(ohlc4, 20))

The 20-bar exponential average of the average price; one of the smoothest lines.

open

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).

CODESCRIPT
plot(close - open)

Signed body size: positive for an up bar, negative for a down bar.

CODESCRIPT
plot(open - prev(close, 1))

The opening gap: the open relative to the previous close.

second

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).

CODESCRIPT
plot(second)

Varies 0-59 on a 1-second chart; always 0 on a 1-minute+ chart.

session.ismarket / ispremarket / ispostmarket

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).

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.

timeframe.period / multiplier / isdaily / isweekly / ismonthly / isintraday / isminutes / isseconds

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.

volume

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.

CODESCRIPT
plot(sma(volume, 20))

The 20-bar average volume; a baseline to compare volume spikes against.

CODESCRIPT
plotshape(volume > sma(volume, 20) * 2, style="circle", location="bottom")

A circle in the bottom band on bars where volume exceeds twice its average.

weekofyear

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.

CODESCRIPT
plot(weekofyear)

Plots each bar's week-of-year (1-53).

year

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.

CODESCRIPT
plot(year)

Plots each bar's year (e.g. 2024).