ScriptingReferenceVariable index

Variable index

A script can read 63 built-in variables. The type shown is the declared type, including its form: a series value changes from bar to bar, a simple value does not change while the script runs.

barstate

VariableTypeDescription
barstate.isfirstseries boolYour script is being evaluated on the first bar of the chart. On every bar after that one, this reads false. A script is evaluated once per bar, in order, so this holds on the earliest run only.
barstate.ishistoryseries boolTells your script whether the bar it is being evaluated on is a historical bar. On a bar that is not historical it reads false. The value is a series, so the answer it gives changes as the script moves from bar to bar.
barstate.islastseries boolThe bar your script is on is the last bar of the chart. On every bar before it, this reads false. It marks a single position in the series rather than a range of bars.
barstate.islastconfirmedhistoryseries boolThis marks the last confirmed historical bar of the chart. Every other bar reads false. It is a separate flag from barstate.islast, which marks the last bar.
barstate.isnewseries boolThe bar being evaluated is a new bar. Where it is not, your script reads false. Read it in a condition, as you would any series value: the answer it gives changes from bar to bar.
barstate.isrealtimeseries boolThe bar under evaluation is still updating rather than closed. Once that bar has closed, your script reads false. It is how your script tells the two kinds of bar apart. If a result must not move once it is drawn, base it on a bar that has closed.

interval

VariableTypeDescription
interval.intervalsimple stringThe interval the chart is drawn on, as a string. Every name in this namespace is simple, so the answer is the same on the first bar and on the last.
interval.isdailysimple boolTrue when the interval is daily.
interval.iseodsimple boolTrue when the interval is an end-of-day interval. This is published as a flag of its own, separate from interval.isdaily. Confirm on the chart which of the two answers your case before you branch on either.
interval.ishourlysimple boolTrue when the interval is hourly.
interval.isintradaysimple boolTrue when the chart’s interval is intraday. Seven of these booleans exist, one per kind of interval, and all seven are simple rather than series.
interval.isminutessimple boolTrue when the interval is measured in minutes. It is narrower than interval.isintraday: both can hold at once, so test the one that matches the question you are asking.
interval.ismonthlysimple boolTrue when the interval is monthly. Together with interval.isweekly and interval.isdaily it covers the intervals a script cannot treat as intraday.
interval.isweeklysimple boolTrue when the interval is weekly.
interval.multipliersimple intThe multiplier of the chart’s interval, as a whole number. Read it alongside interval.interval when you need the size of the interval rather than a yes-or-no answer about its kind.
interval.timeframe_minutessimple intThe chart’s interval counted in minutes. It is the one interval value you can compare arithmetically, which makes it the usual way to write “only on intervals shorter than an hour”.

orderflow

VariableTypeDescription
orderflow.buyseries intHow many buy trades the bar carried. This counts trades, not volume. orderflow.buyvolume measures the volume those trades moved, and the two are separate figures rather than two views of one.
orderflow.buyvolumeseries intThe volume bought in the bar. A bar can carry more buy trades than sell trades while more volume goes the other way, so pick the count or the volume according to the question.
orderflow.cothighseries intThe commitment-of-traders high for the bar, taken from the same per-bar footprint summary as the delta figures.
orderflow.cotlowseries intThe commitment-of-traders low for the bar. The summary these two come from also holds a buy and a sell breakdown of each. Lipi does not expose those, so the high and the low are all a script can read.
orderflow.deltaseries intThe bar’s delta as at its close. For the delta accumulated across a session rather than one bar’s figure, call orderflow.cvd().
orderflow.maxdeltaseries intThe highest delta the bar reached while it was forming. It belongs to that bar alone and starts afresh on the next one, so it is not a running high across the chart.
orderflow.mindeltaseries intThe lowest delta the bar reached while it was forming. Read it with orderflow.maxdelta when you want the swing inside a bar: a bar can close near zero having travelled a long way in both directions, and the closing figure will not show that.
orderflow.sellseries intHow many sell trades the bar carried. The mirror of orderflow.buy, and a count in the same way.
orderflow.sellvolumeseries intThe volume sold in the bar.
orderflow.tradesseries intThe bar’s overall trade count. It is read from the bar’s own footprint totals, not worked out by adding the buy and sell counts together.

session

VariableTypeDescription
session.dateseries stringThe date of the session the current bar falls in. Session values are series, not simple: this one changes as your script moves through bars.
session.isfirstseries boolTrue on the first bar of a session. This is the flag to reach for when something has to reset once per session. The cumulative delta function reads it for exactly that purpose, seeding its running total from zero rather than carrying the previous bar’s total forward.

syminfo

VariableTypeDescription
syminfo.asset_typesimple stringThe instrument’s asset type.
syminfo.currencysimple stringThe currency the instrument is quoted in.
syminfo.exchangesimple stringThe exchange the instrument trades on.
syminfo.isindexsimple boolTrue when the chart instrument is an index. It is the only boolean in the namespace, and like its neighbours it reads na rather than false where the answer is unknown.
syminfo.mincontractsimple intThe instrument’s minimum contract, as a whole number.
syminfo.minmovesimple floatThe instrument’s minimum move, published as a float alongside the minimum tick.
syminfo.minticksimple floatThe instrument’s minimum tick. Dividing a price distance by this converts it into ticks, which is the usual reason to reach for it.
syminfo.pricescalesimple intThe instrument’s price scale.
syminfo.rootsimple stringThe instrument’s root.
syminfo.segmentsimple stringThe segment the instrument belongs to.
syminfo.sizescalesimple intThe instrument’s size scale, the counterpart of its price scale.
syminfo.symbolsimple stringThe instrument’s symbol, published separately from its ticker.
syminfo.tickersimple stringThe chart instrument’s ticker. Every syminfo value is simple — fixed for the whole run of the script — and every one defaults to na where the property is unknown.
syminfo.timezonesimple stringThe instrument’s timezone. It is the value to pass as the timezone argument of the date functions, which each require one.

Bar and chart values

VariableTypeDescription
bar_indexseries intThe index of the bar being evaluated. It is an int series rather than a float, and it changes bar by bar as a price does.
closeseries floatThe bar’s closing price. This is the value most calculations start from. On a bar that has not finished forming, the reading is that bar’s closing value so far.
dayofmonthseries intThe day of the month of the bar being evaluated.
dayofweekseries intThe day of the week of the bar being evaluated. The contract gives the type and not the numbering, so confirm which number means which day before you compare against a literal.
highseries floatThe bar’s highest traded price. Pair it with low when you want the bar’s range; the difference between the two is a series like its parts.
hl2series floatThe bar’s high and low, averaged: its midpoint. Supplied so you need not write the arithmetic. Four of these averaged prices exist. Each is a float series like the values it averages, so one can stand anywhere a price is wanted.
hlc3series floatThe bar’s high, low and close, averaged.
hlcc4series floatThe bar’s high, low and close with the close counted twice, averaged. The name records the weighting: four components, of which two are the close.
hourseries intThe hour of the bar being evaluated.
lowseries floatThe bar’s lowest traded price.
minuteseries intThe minute of the bar being evaluated.
monthseries intThe month of the bar being evaluated. As with the other date parts, there is a function of the same name that takes a time and a timezone instead.
ohlc4series floatThe bar’s four values, open, high, low and close, averaged with equal weight.
oiseries floatOpen interest for the bar. This single name is the whole of the open-interest surface. There is no open-interest namespace and no second name.
openseries floatThe opening price of the bar your script is being evaluated on. It is one of five bar values the interpreter declares together as float series, so it moves on as the script advances through the chart.
secondseries intThe second of the bar being evaluated. Seven date parts are published as variables. weekofyear is not among them: it exists as a function only.
timeseries intThe bar’s opening time, as an int series. It counts milliseconds from the Unix epoch. Note the unit: it is milliseconds, not seconds, so anything expecting seconds needs the value divided by a thousand first. Hand it to one of the date functions - year, month, hour and the rest - together with a timezone to take it apart.
time_closeseries intThe bar’s closing time, published separately from time. It is the opening time advanced by one interval, in the same unit: milliseconds from the Unix epoch. Both are int series, so a script can compare the two or pass either to a date function.
timenowseries intThe current time, rather than a time taken from the bar. It is the instant the script ran, in milliseconds from the Unix epoch, and it is typed as a series like the bar’s own time values.
volumeseries floatThe volume traded in the bar. It is a float rather than an int, so it carries fractional volumes without a conversion.
yearseries intThe year of the bar being evaluated. A function of the same name also exists. The variable reads the current bar; the function reads whatever time you hand it.
Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade