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
| Variable | Type | Description |
|---|---|---|
barstate.isfirst | series bool | Your 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.ishistory | series bool | Tells 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.islast | series bool | The 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.islastconfirmedhistory | series bool | This 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.isnew | series bool | The 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.isrealtime | series bool | The 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
| Variable | Type | Description |
|---|---|---|
interval.interval | simple string | The 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.isdaily | simple bool | True when the interval is daily. |
interval.iseod | simple bool | True 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.ishourly | simple bool | True when the interval is hourly. |
interval.isintraday | simple bool | True 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.isminutes | simple bool | True 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.ismonthly | simple bool | True when the interval is monthly. Together with interval.isweekly and interval.isdaily it covers the intervals a script cannot treat as intraday. |
interval.isweekly | simple bool | True when the interval is weekly. |
interval.multiplier | simple int | The 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_minutes | simple int | The 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
| Variable | Type | Description |
|---|---|---|
orderflow.buy | series int | How 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.buyvolume | series int | The 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.cothigh | series int | The commitment-of-traders high for the bar, taken from the same per-bar footprint summary as the delta figures. |
orderflow.cotlow | series int | The 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.delta | series int | The bar’s delta as at its close. For the delta accumulated across a session rather than one bar’s figure, call orderflow.cvd(). |
orderflow.maxdelta | series int | The 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.mindelta | series int | The 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.sell | series int | How many sell trades the bar carried. The mirror of orderflow.buy, and a count in the same way. |
orderflow.sellvolume | series int | The volume sold in the bar. |
orderflow.trades | series int | The 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
| Variable | Type | Description |
|---|---|---|
session.date | series string | The 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.isfirst | series bool | True 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
| Variable | Type | Description |
|---|---|---|
syminfo.asset_type | simple string | The instrument’s asset type. |
syminfo.currency | simple string | The currency the instrument is quoted in. |
syminfo.exchange | simple string | The exchange the instrument trades on. |
syminfo.isindex | simple bool | True 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.mincontract | simple int | The instrument’s minimum contract, as a whole number. |
syminfo.minmove | simple float | The instrument’s minimum move, published as a float alongside the minimum tick. |
syminfo.mintick | simple float | The instrument’s minimum tick. Dividing a price distance by this converts it into ticks, which is the usual reason to reach for it. |
syminfo.pricescale | simple int | The instrument’s price scale. |
syminfo.root | simple string | The instrument’s root. |
syminfo.segment | simple string | The segment the instrument belongs to. |
syminfo.sizescale | simple int | The instrument’s size scale, the counterpart of its price scale. |
syminfo.symbol | simple string | The instrument’s symbol, published separately from its ticker. |
syminfo.ticker | simple string | The 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.timezone | simple string | The 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
| Variable | Type | Description |
|---|---|---|
bar_index | series int | The 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. |
close | series float | The 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. |
dayofmonth | series int | The day of the month of the bar being evaluated. |
dayofweek | series int | The 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. |
high | series float | The 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. |
hl2 | series float | The 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. |
hlc3 | series float | The bar’s high, low and close, averaged. |
hlcc4 | series float | The 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. |
hour | series int | The hour of the bar being evaluated. |
low | series float | The bar’s lowest traded price. |
minute | series int | The minute of the bar being evaluated. |
month | series int | The 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. |
ohlc4 | series float | The bar’s four values, open, high, low and close, averaged with equal weight. |
oi | series float | Open 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. |
open | series float | The 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. |
second | series int | The second of the bar being evaluated. Seven date parts are published as variables. weekofyear is not among them: it exists as a function only. |
time | series int | The 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_close | series int | The 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. |
timenow | series int | The 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. |
volume | series float | The volume traded in the bar. It is a float rather than an int, so it carries fractional volumes without a conversion. |
year | series int | The 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.