data reference
Provides market-data sources, subscription records, and snapshot query receivers for confirmed, forming, and trade data.
Provides market-data sources, subscription records, and snapshot query receivers for confirmed, forming, and trade data.
Accepted values
These named values are the complete choices accepted by parameters of each type.
BookUnit
bookunit.baseSelects base quantity for book imbalance calculations.bookunit.quoteSelects quote value for book imbalance calculations.VolBasis
volbasis.totalRanks profile levels by total (buy + sell) volume.volbasis.buyRanks profile levels by buy volume.volbasis.sellRanks profile levels by sell volume.volbasis.deltaAbsRanks profile levels by |buy - sell| (absolute per-level delta).data.ohlcv
source data.ohlcv -> OhlcvSubSubscribes to price and volume bars.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0,0s, ortime.seconds(0)) asks for live data only: nothing is loaded before the script goes live, handlers on this subscription run only on live updates, and reads return null until then. A live-only subscription does not make the chart's history finer. A negative constant is an error; a negative input value also means live data only. During the history replay itsisHistoryreads true. Once live, a live-only subscription finer than the chart adds its updates to the chart's live history, so the chart keeps fewer of its own bars after running for a while. The chart subscription (no exchange, symbol, or timeframe) cannot be live only. A live-only subscription with the same market and timeframe as one the script needs for a.formingread of a longer timeframe loads history like a normal subscription.
Completed bars and the current forming bar are available. history can raise
the amount of data loaded before the visible range so indicators have enough
samples at the left edge. A positive value cannot reduce the default of 750
intraday bars. A longer history can help an EMA settle. Calculations still
return null until they have enough samples.
Example
script "Data OHLCV Example"
data chart = subscribe(data.ohlcv)
on chart.update {
let close = chart.close ?? 0.0
}data.oi
source data.oi -> OiSubSubscribes to open interest bars.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0,0s, ortime.seconds(0)) asks for live data only: nothing is loaded before the script goes live, handlers on this subscription run only on live updates, and reads return null until then. A live-only subscription does not make the chart's history finer. A negative constant is an error; a negative input value also means live data only. During the history replay itsisHistoryreads true. Once live, a live-only subscription finer than the chart adds its updates to the chart's live history, so the chart keeps fewer of its own bars after running for a while.
Completed bars and the current forming bar are available. history can raise
the amount of data loaded before the visible range so indicators have enough
samples at the left edge. A positive value cannot reduce the default of 750
intraday bars. A longer history can help an EMA settle. Calculations still
return null until they have enough samples.
Example
script "Data OI Example"
data oi = subscribe(data.oi)
on oi.update {
let close = oi.close ?? 0.0
}data.vd
source data.vd -> VdSubSubscribes to volume delta bars.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0,0s, ortime.seconds(0)) asks for live data only: nothing is loaded before the script goes live, handlers on this subscription run only on live updates, and reads return null until then. A live-only subscription does not make the chart's history finer. A negative constant is an error; a negative input value also means live data only. During the history replay itsisHistoryreads true. Once live, a live-only subscription finer than the chart adds its updates to the chart's live history, so the chart keeps fewer of its own bars after running for a while.bucketselects a size group from 1 to 11, defaulting to 1. Other values are rejected before the script runs.
Completed bars and the current forming bar are available. history can raise
the amount of data loaded before the visible range so indicators have enough
samples at the left edge. A positive value cannot reduce the default of 750
intraday bars. A longer history can help an EMA settle. Calculations still
return null until they have enough samples.
Contracts
bucket: Accepted range: 1 to 11. Invalid values are rejected.
Example
script "Data VD Example"
data vd = subscribe(data.vd)
on vd.update {
let close = vd.close ?? 0.0
}data.cvd
source data.cvd -> CvdSubSubscribes to cumulative volume delta bars.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0,0s, ortime.seconds(0)) asks for live data only: nothing is loaded before the script goes live, handlers on this subscription run only on live updates, and reads return null until then. A live-only subscription does not make the chart's history finer. A negative constant is an error; a negative input value also means live data only. During the history replay itsisHistoryreads true. Once live, a live-only subscription finer than the chart adds its updates to the chart's live history, so the chart keeps fewer of its own bars after running for a while.bucketselects a size group from 1 to 11, defaulting to 1. Other values are rejected before the script runs.
Completed bars and the current forming bar are available. history can raise
the amount of data loaded before the visible range so indicators have enough
samples at the left edge. A positive value cannot reduce the default of 750
intraday bars. A longer history can help an EMA settle. Calculations still
return null until they have enough samples.
Contracts
bucket: Accepted range: 1 to 11. Invalid values are rejected.
Example
script "Data CVD Example"
data cvd = subscribe(data.cvd)
on cvd.update {
let close = cvd.close ?? 0.0
}data.stat
source data.stat -> StatSubSubscribes to market statistics bars.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0,0s, ortime.seconds(0)) asks for live data only: nothing is loaded before the script goes live, handlers on this subscription run only on live updates, and reads return null until then. A live-only subscription does not make the chart's history finer. A negative constant is an error; a negative input value also means live data only. During the history replay itsisHistoryreads true. Once live, a live-only subscription finer than the chart adds its updates to the chart's live history, so the chart keeps fewer of its own bars after running for a while.
Completed bars and the current forming bar are available. history can raise
the amount of data loaded before the visible range so indicators have enough
samples at the left edge. A positive value cannot reduce the default of 750
intraday bars. A longer history can help an EMA settle. Calculations still
return null until they have enough samples.
Example
script "Data Stat Example"
data stat = subscribe(data.stat)
on stat.update {
let mark = stat.markPrice ?? 0.0
}data.book
source data.book -> BookSubProvides order-book snapshots to read from another subscription's handler.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0or0s) asks for live data only: no earlier snapshots are loaded, and reads return snapshots from the period the script started in onward. A negative constant is an error.
Read snapshots from a handler on another subscription. An explicit timeframe
sets the snapshot periods independently of the chart. barsAgo counts these
source periods. Reads use the latest source boundary at or before the handler's
time. Missing periods return null. Higher-timeframe reads use completed periods;
they do not reveal the final contents of a period still in progress.
Each book period uses its latest high-definition snapshot, not an average.
A positive history can raise the default history request but cannot reduce
it. Initial snapshot history loads up to 250 source periods, separately from
the chart's replay range, and is also limited by the source's available
history.
Example
script "Data Book Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bid = book.bestBid() ?? 0.0
}data.volume
source data.volume -> VolumeSubProvides volume-profile snapshots to read from another subscription's handler.
exchange,symbol, andtimeframechoose the market and period. Omit them or use null to inherit the chart's settings, the window's settings, or the run settings when there is no chart or window.historyrequests earlier data as a number of source periods or a duration. Null uses the default. Zero (0or0s) asks for live data only: no earlier snapshots are loaded, and reads return snapshots from the period the script started in onward. A negative constant is an error.
Read snapshots from a handler on another subscription. An explicit timeframe
sets the snapshot periods independently of the chart. barsAgo counts these
source periods. Reads use the latest source boundary at or before the handler's
time. Missing periods return null. Higher-timeframe reads use completed periods;
they do not reveal the final contents of a period still in progress.
Higher timeframes may use wider price bins. Read their width with binSize().
There is no forming volume-profile view.
A positive history can raise the default history request but cannot reduce
it. Initial snapshot history loads up to 250 source periods, separately from
the chart's replay range, and is also limited by the source's available
history.
Example
script "Data Volume Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let summary = vol.summary(0)
}OhlcvSub
OHLCV subscription record.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | true | Opening time of the confirmed bar. [n] looks back by this subscription's periods. |
open | float? | true | Confirmed open price. |
high | float? | true | Confirmed high price. |
low | float? | true | Confirmed low price. |
close | float? | true | Confirmed close price. |
volume | float? | true | Confirmed total volume. |
buyVolume | float? | true | Confirmed buy volume. |
sellVolume | float? | true | Confirmed sell volume. |
buyCount | int? | true | Confirmed buy trade count. |
sellCount | int? | true | Confirmed sell trade count. |
trades | int? | true | Confirmed trade count. |
forming | OhlcvForming | false | Current forming OHLCV values. Read these values directly; history indexing with [n] is not supported. |
isNew | bool | false | True during an update in which this subscription confirmed at least one period. |
isRealtime | bool | false | True while the forming period receives live updates. |
isHistory | bool | false | True during history replay. |
isFirst | bool | false | True when index == 0. |
index | int | false | Position of the current reference period in the loaded history, counting from 0. |
isLast | bool | false | True during live updates of the last loaded period, which is still forming. Always false during historical replay and inside on X.close, including the transition to live data. Use it in on X.update to draw only at the live edge. |
OhlcvForming
Price and volume values for the current forming bar.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | false | Opening time of the forming bar. |
open | float? | false | Forming open price. |
high | float? | false | Forming high price. |
low | float? | false | Forming low price. |
close | float? | false | Forming close price. |
volume | float? | false | Forming total volume. |
buyVolume | float? | false | Forming buy volume. |
sellVolume | float? | false | Forming sell volume. |
buyCount | int? | false | Forming buy trade count. |
sellCount | int? | false | Forming sell trade count. |
trades | int? | false | Forming trade count. |
OiSub
Open-interest subscription record.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | true | Opening time of the confirmed bar. |
open | float? | true | Confirmed open-interest open value. |
high | float? | true | Confirmed open-interest high value. |
low | float? | true | Confirmed open-interest low value. |
close | float? | true | Confirmed open-interest close value. |
forming | OiForming | false | Current forming open-interest values. Read these values directly; history indexing with [n] is not supported. |
isNew | bool | false | True during an update in which this subscription confirmed at least one period. |
isRealtime | bool | false | True while the forming period receives live updates. |
isHistory | bool | false | True during history replay. |
isFirst | bool | false | True when index == 0. |
index | int | false | Position of the current reference period in the loaded history, counting from 0. |
isLast | bool | false | True during live updates of the last loaded period, which is still forming. Always false during historical replay and inside on X.close, including the transition to live data. Use it in on X.update to draw only at the live edge. |
OiForming
Open-interest values for the current forming bar.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | false | Opening time of the forming bar. |
open | float? | false | Forming open-interest open value. |
high | float? | false | Forming open-interest high value. |
low | float? | false | Forming open-interest low value. |
close | float? | false | Forming open-interest close value. |
VdSub
Volume-delta subscription record.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | true | Opening time of the confirmed bar. |
open | float? | true | Confirmed volume-delta open value. |
high | float? | true | Confirmed volume-delta high value. |
low | float? | true | Confirmed volume-delta low value. |
close | float? | true | Confirmed volume-delta close value. |
bucket | int | false | Volume-delta bucket group. |
bucketLabel | string | false | Volume-delta bucket label. |
bucketMinUsd | float? | false | Volume-delta bucket minimum USD notional. |
bucketMaxUsd | float? | false | Volume-delta bucket maximum USD notional. |
forming | VdForming | false | Current forming volume-delta values. Read these values directly; history indexing with [n] is not supported. |
isNew | bool | false | True during an update in which this subscription confirmed at least one period. |
isRealtime | bool | false | True while the forming period receives live updates. |
isHistory | bool | false | True during history replay. |
isFirst | bool | false | True when index == 0. |
index | int | false | Position of the current reference period in the loaded history, counting from 0. |
isLast | bool | false | True during live updates of the last loaded period, which is still forming. Always false during historical replay and inside on X.close, including the transition to live data. Use it in on X.update to draw only at the live edge. |
VdForming
Volume-delta values for the current forming bar.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | false | Opening time of the forming bar. |
open | float? | false | Forming volume-delta open value. |
high | float? | false | Forming volume-delta high value. |
low | float? | false | Forming volume-delta low value. |
close | float? | false | Forming volume-delta close value. |
bucket | int | false | Volume-delta bucket group. |
bucketLabel | string | false | Volume-delta bucket label. |
bucketMinUsd | float? | false | Volume-delta bucket minimum USD notional. |
bucketMaxUsd | float? | false | Volume-delta bucket maximum USD notional. |
CvdSub
Cumulative volume-delta data for this script run.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | true | Opening time of the confirmed bar. |
open | float? | true | Confirmed cumulative volume-delta open value. |
high | float? | true | Confirmed cumulative volume-delta high value. |
low | float? | true | Confirmed cumulative volume-delta low value. |
close | float? | true | Confirmed cumulative volume-delta close value. |
bucket | int | false | CVD bucket group. |
bucketLabel | string | false | CVD bucket label. |
bucketMinUsd | float? | false | CVD bucket minimum USD notional. |
bucketMaxUsd | float? | false | CVD bucket maximum USD notional. |
forming | CvdForming | false | Current forming CVD values. Read these values directly; history indexing with [n] is not supported. |
isNew | bool | false | True during an update in which this subscription confirmed at least one period. |
isRealtime | bool | false | True while the forming period receives live updates. |
isHistory | bool | false | True during history replay. |
isFirst | bool | false | True when index == 0. |
index | int | false | Position of the current reference period in the loaded history, counting from 0. |
isLast | bool | false | True during live updates of the last loaded period, which is still forming. Always false during historical replay and inside on X.close, including the transition to live data. Use it in on X.update to draw only at the live edge. |
CvdForming
Cumulative volume-delta values for the current forming bar.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | false | Opening time of the forming bar. |
open | float? | false | Forming cumulative volume-delta open value. |
high | float? | false | Forming cumulative volume-delta high value. |
low | float? | false | Forming cumulative volume-delta low value. |
close | float? | false | Forming cumulative volume-delta close value. |
bucket | int | false | CVD bucket group. |
bucketLabel | string | false | CVD bucket label. |
bucketMinUsd | float? | false | CVD bucket minimum USD notional. |
bucketMaxUsd | float? | false | CVD bucket maximum USD notional. |
StatSub
Market-statistics subscription record.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | true | Opening time of the confirmed statistics bar. |
sellLiq | float? | true | Confirmed sell liquidation value. |
buyLiq | float? | true | Confirmed buy liquidation value. |
markPrice | float? | true | Confirmed mark price. Null when the feed carries no mark; aggregate exchange specs never have one. |
fundingRate | float? | true | Confirmed funding rate. |
forming | StatForming | false | Current last-value statistics view. Read these values directly; history indexing with [n] is not supported. |
isNew | bool | false | True during an update in which this subscription confirmed at least one period. |
isRealtime | bool | false | True while the forming period receives live updates. |
isHistory | bool | false | True during history replay. |
isFirst | bool | false | True when index == 0. |
index | int | false | Position of the current reference period in the loaded history, counting from 0. |
isLast | bool | false | True during live updates of the last loaded period, which is still forming. Always false during historical replay and inside on X.close, including the transition to live data. Use it in on X.update to draw only at the live edge. |
StatForming
Latest market-statistics values for the current forming bar.
| Field | Type | History | Description |
|---|---|---|---|
time | time? | false | Opening time of the forming statistics bar. |
sellLiq | float? | false | Last-value sell liquidation value. |
buyLiq | float? | false | Last-value buy liquidation value. |
markPrice | float? | false | Last-value mark price. Null when the feed carries no mark; aggregate exchange specs never have one. |
fundingRate | float? | false | Last-value funding rate. |
BookSub
Order-book snapshots read through subscription methods.
| Field | Type | History | Description |
|---|
VolumeSub
Volume-profile snapshots read through subscription methods.
| Field | Type | History | Description |
|---|
BookDepth
Describes order-book depth over a price band.
| Field | Type | History | Description |
|---|---|---|---|
time | time | false | Start time of the snapshot period. |
binSize | float | false | Book price-bin size. |
bidQty | float | false | Bid quantity in the query range. |
askQty | float | false | Ask quantity in the query range. |
bidValue | float | false | Bid quote value in the query range. |
askValue | float | false | Ask quote value in the query range. |
bidLevels | int | false | Bid levels included in the query range. |
askLevels | int | false | Ask levels included in the query range. |
bidMinPrice | float? | false | Lowest bid price included, or null when empty. |
bidMaxPrice | float? | false | Highest bid price included, or null when empty. |
askMinPrice | float? | false | Lowest ask price included, or null when empty. |
askMaxPrice | float? | false | Highest ask price included, or null when empty. |
deltaQty | float | false | Bid quantity minus ask quantity. |
deltaValue | float | false | Bid value minus ask value. |
totalQty | float | false | Bid plus ask quantity. |
totalValue | float | false | Bid plus ask value. |
ratioQty | float | false | Quantity imbalance ratio; NaN when total quantity is 0. |
ratioValue | float | false | Value imbalance ratio; NaN when total value is 0. |
ratio | float | false | Default quote-value imbalance ratio; NaN when total value is 0. |
VolumeSummary
Summarizes a volume-profile snapshot.
| Field | Type | History | Description |
|---|---|---|---|
time | time | false | Start time of the snapshot period. |
binSize | float | false | Volume-profile price-bin size. |
levels | int | false | Number of profile levels included. |
minPrice | float | false | Lowest profile price included. |
maxPrice | float | false | Highest profile price included. |
buy | float | false | Buy volume. |
sell | float | false | Sell volume. |
total | float | false | Total volume. |
delta | float | false | Buy volume minus sell volume. |
ratio | float | false | Volume-delta ratio; NaN when total volume is 0. |
VolumeLevel
Represents one volume-profile level.
| Field | Type | History | Description |
|---|---|---|---|
time | time | false | Start time of the snapshot period. |
binSize | float | false | Volume-profile price-bin size. |
index | int | false | 0-based level index, ascending by price. |
price | float | false | Level price. |
buy | float | false | Buy volume at this level. |
sell | float | false | Sell volume at this level. |
total | float | false | Buy plus sell volume. |
delta | float | false | Buy volume minus sell volume. |
ratio | float | false | Volume-delta ratio; NaN when total volume is 0. |
BookLevel
One order-book price level.
| Field | Type | History | Description |
|---|---|---|---|
index | int | false | 0-based level index within the side, 0 = best. |
price | float | false | Level price. |
qty | float | false | Level quantity. |
value | float | false | Total value at this level: price * qty. |
FootprintBucket
One price bucket containing grouped volume.
| Field | Type | History | Description |
|---|---|---|---|
index | int | false | 0-based bucket index, ascending by price. |
from | float | false | Inclusive lower price bound of the bucket. |
to | float | false | Exclusive upper price bound of the bucket. |
buy | float | false | Buy volume re-binned into the bucket. |
sell | float | false | Sell volume re-binned into the bucket. |
total | float | false | Total volume: buy + sell. |
delta | float | false | Volume delta: buy - sell. |
BookLevels
Price levels on one side of the order book.
| Field | Type | History | Description |
|---|---|---|---|
len | int | false | Number of levels in the view; raw depth may be capped by your data plan. |
time | time | false | Start time of the snapshot period. |
binSize | float | false | Book price-bin size. |
VolumeLevels
Price levels in a volume profile.
| Field | Type | History | Description |
|---|---|---|---|
len | int | false | Number of stored profile levels in the view. |
time | time | false | Start time of the snapshot period. |
binSize | float | false | Volume-profile price-bin size. |
VolumeBuckets
Volume grouped into price buckets.
Read the results in a for loop or a local let variable within the handler. They cannot be saved in state, record fields, or collections, passed to another function, or returned from one.
| Field | Type | History | Description |
|---|---|---|---|
len | int | false | Number of buckets in the view. |
time | time | false | Start time of the snapshot period. |
binSize | float | false | Finest source price-bin size of the re-binned snapshot. |
data.book.bids
data.book.bids(barsAgo: int = 0) -> BookLevels?Returns bid levels, starting with the best price.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Levels are sorted highest to lowest price. A snapshot with no bids returns an
empty view with len == 0.
Read the results in a for loop or a local let variable within the handler.
They cannot be saved in state, record fields, or collections, passed to another
function, or returned from one.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Bids Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bids = book.bids()
if bids != null {
for lvl in bids {
let value = lvl.value
}
}
}data.book.asks
data.book.asks(barsAgo: int = 0) -> BookLevels?Returns ask levels, starting with the best price.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Levels are sorted lowest to highest price. A snapshot with no asks returns an
empty view with len == 0.
Read the results in a for loop or a local let variable within the handler.
They cannot be saved in state, record fields, or collections, passed to another
function, or returned from one.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Asks Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let asks = book.asks()
if asks != null {
let touch = asks.get(0)
}
}data.volume.levels
data.volume.levels(barsAgo: int = 0) -> VolumeLevels?Returns volume-profile levels from lowest to highest price.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Contains the traded levels, matching level(index, barsAgo:) one by one. A
snapshot with no levels returns an empty view with len == 0. These results
include all profile levels; the order-book depth limit does not apply.
Read the results in a for loop or a local let variable within the handler.
They cannot be saved in state, record fields, or collections, passed to another
function, or returned from one.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Levels Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let lvls = vol.levels()
if lvls != null {
for lvl in lvls {
// lvl.total == lvl.buy + lvl.sell; lvl.ratio is NaN when total == 0
}
}
}data.volume.buckets
data.volume.buckets(count: int, from: number? = null, to: number? = null, barsAgo: int = 0) -> VolumeBuckets?Groups volume into equal-width price buckets.
count chooses the number of buckets. They span from the lowest selected
price through one binSize above the highest. Each level goes into the bucket
containing its price, so bucket totals add up to the selected range's totals.
A count below 1 or above 4096 returns null.
from and to select the price range first, including both ends. Null leaves
that end unrestricted. An empty range or reversed bounds returns null.
barsAgo chooses the snapshot; a missing snapshot returns null.
Read the values you need before calling buckets or bucketsByLevels again
during the same calculation step. A later call replaces the data read through
earlier bucket views, even on another snapshot or profile. Request the buckets
again when you need a fresh view.
Contracts
count: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Buckets Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let b = vol.buckets(4)
if b != null {
for bkt in b {
// bkt.total == bkt.buy + bkt.sell over [bkt.from, bkt.to)
}
}
}data.volume.bucketsByLevels
data.volume.bucketsByLevels(levelsPerBucket: int, from: number? = null, to: number? = null, barsAgo: int = 0) -> VolumeBuckets?Groups consecutive price levels into volume buckets.
levelsPerBucket chooses how many levels to put in each bucket. The last bucket
can contain fewer levels. Each bucket starts at its first level's price and
ends one binSize above its last level. A value below 1 returns null.
from and to select the price range first, including both ends. Null leaves
that end unrestricted. An empty range or reversed bounds returns null.
barsAgo chooses the snapshot; a missing snapshot returns null.
Read the values you need before calling buckets or bucketsByLevels again
during the same calculation step. A later call replaces the data read through
earlier bucket views, even on another snapshot or profile. Request the buckets
again when you need a fresh view.
Contracts
levelsPerBucket: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Buckets By Levels Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let b = vol.bucketsByLevels(8)
if b != null {
let first = b.get(0)
}
}data.volume.bucketsByStep
data.volume.bucketsByStep(step: float, from: number? = null, to: number? = null, barsAgo: int = 0) -> VolumeBuckets?Groups volume into price buckets of a fixed size on a shared price grid.
step is the height of every bucket. Buckets start at whole multiples of
step, so the same price always falls in the same bucket, on every snapshot.
The first bucket is the one containing the lowest selected price and the last is
the one containing the highest. Buckets between them with no volume are included
with zero volume. A step that is zero, negative, or not finite returns null,
as does a range that needs more than 4096 buckets.
from and to select the price range first, including both ends. Null leaves
that end unrestricted. An empty range or reversed bounds returns null.
barsAgo chooses the snapshot; a missing snapshot returns null.
The view's time is the start of the snapshot's period, which is the time to
pass when drawing the buckets as cells on that period's bar.
Read the values you need before calling buckets, bucketsByLevels, or
bucketsByStep again during the same calculation step. A later call replaces
the data read through earlier bucket views, even on another snapshot or profile.
Request the buckets again when you need a fresh view.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Buckets By Step Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let b = vol.bucketsByStep(25.0)
if b != null {
for bkt in b {
// bkt.from is a whole multiple of 25.0
}
}
}data.bookLevels.get
data.bookLevels.get(index: int) -> BookLevel?Reads an order-book level by index.
index counts from 0, starting with the best price. A negative index or one at
or beyond len returns null. view[i] is equivalent to view.get(i).
The level's value equals price * qty.
Contracts
index: Accepted range: 0 up to but not including len. Invalid values returnnull.
Example
script "Data Book Levels Get Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bids = book.bids()
if bids != null {
let best = bids.get(0)
}
}data.volumeLevels.get
data.volumeLevels.get(index: int) -> VolumeLevel?Reads a volume-profile level by index.
index counts from 0, starting with the lowest price. A negative index or one
at or beyond len returns null. view[i] is equivalent to view.get(i).
The fields match level(index, barsAgo:) for the same snapshot. The level's
ratio is NaN when its total volume is zero.
Contracts
index: Accepted range: 0 up to but not including len. Invalid values returnnull.
Example
script "Data Volume Levels Get Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let lvls = vol.levels()
if lvls != null {
let lowest = lvls.get(0)
}
}data.volumeBuckets.get
data.volumeBuckets.get(index: int) -> FootprintBucket?Reads a volume bucket by index.
index counts from 0, starting with the lowest price range. A negative index
or one at or beyond len returns null. view[i] is equivalent to view.get(i).
total is buy + sell; delta is buy - sell.
A later buckets or bucketsByLevels call during the same calculation step
replaces the data read through this view, even if it uses another snapshot
or profile.
Contracts
index: Accepted range: 0 up to but not including len. Invalid values returnnull.
Example
script "Data Volume Buckets Get Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let b = vol.buckets(4)
if b != null {
let first = b.get(0)
}
}BookSideSummary
Describes one order-book side over a price band.
| Field | Type | History | Description |
|---|---|---|---|
time | time | false | Start time of the snapshot period. |
binSize | float | false | Book price-bin size. |
levels | int | false | Levels included in the band. |
qty | float | false | Total quantity in the band. |
value | float | false | Total quote value, summed as price times quantity in the band. |
avgPrice | float | false | Quantity-weighted average price of the band (ladder VWAP): value / qty. |
minPrice | float | false | Lowest level price included. |
maxPrice | float | false | Highest level price included. |
VolumeArea
Describes a volume-profile value area.
| Field | Type | History | Description |
|---|---|---|---|
pocPrice | float | false | Price with the largest value for the selected basis. Ties use the lowest price. |
lowPrice | float | false | Value-area low (VAL). |
highPrice | float | false | Value-area high (VAH). |
buy | float | false | Buy volume over the queried band. |
sell | float | false | Sell volume over the queried band. |
total | float | false | Total volume over the queried band. |
delta | float | false | Buy minus sell volume over the queried band. |
ratio | float | false | Volume-delta ratio over the queried band (NaN when total is 0). |
levels | int | false | Distinct price levels in the queried band. |
data.ohlcv.change
data.ohlcv.change() -> float?Returns the change from open to close on the confirmed bar.
Calculates close - open for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data OHLCV Change Example"
data chart = subscribe(data.ohlcv)
on chart.update {
let move = chart.change()
}data.ohlcv.range
data.ohlcv.range() -> float?Returns the high-to-low range of the confirmed bar.
Calculates high - low for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data OHLCV Range Example"
data chart = subscribe(data.ohlcv)
on chart.update {
let span = chart.range()
}data.ohlcv.delta
data.ohlcv.delta() -> float?Returns the current OHLCV buy-sell volume delta.
Calculates buyVolume - sellVolume for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data OHLCV Delta Example"
data chart = subscribe(data.ohlcv)
on chart.update {
let volDelta = chart.delta()
}data.ohlcv.tradeDelta
data.ohlcv.tradeDelta() -> int?Returns the current OHLCV buy-sell trade-count delta.
Calculates buyCount - sellCount for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data OHLCV Trade Delta Example"
data chart = subscribe(data.ohlcv)
on chart.update {
let countDelta = chart.tradeDelta()
}data.oi.change
data.oi.change() -> float?Returns the change from open to close on the confirmed bar.
Calculates close - open for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data OI Change Example"
data oi = subscribe(data.oi)
on oi.update {
let move = oi.change()
}data.oi.range
data.oi.range() -> float?Returns the high-to-low range of the confirmed bar.
Calculates high - low for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data OI Range Example"
data oi = subscribe(data.oi)
on oi.update {
let span = oi.range()
}data.vd.change
data.vd.change() -> float?Returns the change from open to close on the confirmed bar.
Calculates close - open for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data VD Change Example"
data vd = subscribe(data.vd)
on vd.update {
let move = vd.change()
}data.vd.range
data.vd.range() -> float?Returns the high-to-low range of the confirmed bar.
Calculates high - low for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data VD Range Example"
data vd = subscribe(data.vd)
on vd.update {
let span = vd.range()
}data.cvd.change
data.cvd.change() -> float?Returns the change from open to close on the confirmed bar.
Calculates close - open for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data CVD Change Example"
data cvd = subscribe(data.cvd)
on cvd.update {
let move = cvd.change()
}data.cvd.range
data.cvd.range() -> float?Returns the high-to-low range of the confirmed bar.
Calculates high - low for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data CVD Range Example"
data cvd = subscribe(data.cvd)
on cvd.update {
let span = cvd.range()
}data.stat.liqDelta
data.stat.liqDelta() -> float?Returns the current buy-sell liquidation delta.
Calculates buyLiq - sellLiq for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data Stat Liq Delta Example"
data stat = subscribe(data.stat)
on stat.update {
let liqDelta = stat.liqDelta()
}data.stat.liqTotal
data.stat.liqTotal() -> float?Returns the current total liquidation value.
Calculates buyLiq + sellLiq for this subscription's current confirmed bar.
Returns null if the bar or either field is unavailable.
Example
script "Data Stat Liq Total Example"
data stat = subscribe(data.stat)
on stat.update {
let liqTotal = stat.liqTotal()
}data.book.depth
data.book.depth(outerPct: float, ref: number? = null, innerPct: float? = null, barsAgo: int = 0) -> BookDepth?Summarizes order-book depth around a price.
outerPctsets the distance on either side ofref, as a percentage: fromref * (1 - outerPct/100)toref * (1 + outerPct/100). Values outside its allowed range stop the script with an error.refdefaults to the mid price. Without both a bid and an ask, the default reference is unavailable and the result is null.innerPctoptionally excludes prices strictly inside a smaller band around the reference. Null or zero excludes nothing.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
An empty price band or unavailable book data also returns null. Read this from
another subscription's handler; book subscriptions have no handlers.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
outerPct: Accepted range: 0.0 or greater. Must be a finite number. Invalid values are rejected.barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Depth Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let depth = book.depth(1.0, barsAgo: 0)
}data.book.time
data.book.time(barsAgo: int = 0) -> time?Returns the start time of the book snapshot period.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Time Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let t = book.time()
}data.book.binSize
data.book.binSize(barsAgo: int = 0) -> float?Returns the width of each book price bin.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Bin Size Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bin = book.binSize()
}data.book.numBids
data.book.numBids(barsAgo: int = 0) -> int?Counts the bid levels in a book snapshot.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
A snapshot with no bids returns 0.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Num Bids Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let n = book.numBids()
}data.book.numAsks
data.book.numAsks(barsAgo: int = 0) -> int?Counts the ask levels in a book snapshot.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
A snapshot with no asks returns 0.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Num Asks Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let n = book.numAsks()
}data.book.bestBid
data.book.bestBid(barsAgo: int = 0) -> float?Returns the highest bid price.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
A snapshot with no bids returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Best Bid Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bb = book.bestBid()
}data.book.bestAsk
data.book.bestAsk(barsAgo: int = 0) -> float?Returns the lowest ask price.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
A snapshot with no asks returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Best Ask Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let ba = book.bestAsk()
}data.book.mid
data.book.mid(barsAgo: int = 0) -> float?Returns the midpoint between the best bid and ask.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Calculates (bestBid + bestAsk) / 2. Returns null if either side is empty.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Mid Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let mid = book.mid()
}data.book.spread
data.book.spread(barsAgo: int = 0) -> float?Returns the gap between the best ask and bid.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Calculates bestAsk - bestBid. Returns null if either side is empty.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Spread Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let sp = book.spread()
}data.book.imbalance
data.book.imbalance(outerPct: float, unit: BookUnit = 2, ref: number? = null, innerPct: float? = null, barsAgo: int = 0) -> float?Returns the balance between bids and asks around a price.
outerPctsets the price band, as fordepth. Values outside its allowed range stop the script with an error.unitchooses quote value (bookunit.quote, the default) or base quantity (bookunit.base).refdefaults to the mid price.innerPctdefaults to null.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Returns (bid - ask) / (bid + ask). Quote units match depth(...).ratioValue;
base units match depth(...).ratioQty. A zero total gives NaN. The result is
null whenever the corresponding depth call is null.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
outerPct: Accepted range: 0.0 or greater. Must be a finite number. Invalid values are rejected.barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Imbalance Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let imb = book.imbalance(1.0)
let qtyImb = book.imbalance(1.0, unit: bookunit.base)
}Accepted values
unit:BookUnitvalues — 2 available.
data.book.range
data.book.range(from: float, to: float, barsAgo: int = 0) -> BookDepth?Summarizes both bid and ask levels within a price range.
from and to include both ends of the range. Reversed bounds or a range
with no levels returns null. Unavailable book data also returns null.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Range Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let mid = book.mid()
if mid != null {
let band = book.range(mid - 5.0, mid + 5.0)
}
}data.book.bidRange
data.book.bidRange(from: float, to: float, barsAgo: int = 0) -> BookSideSummary?Summarizes bid levels within a price range.
from and to include both ends of the range. Reversed bounds or a range
with no levels returns null. Unavailable book data also returns null.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
avgPrice is the quantity-weighted average price of the selected levels.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Bid Range Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bids = book.bidRange(90.0, 100.0)
}data.book.askRange
data.book.askRange(from: float, to: float, barsAgo: int = 0) -> BookSideSummary?Summarizes ask levels within a price range.
from and to include both ends of the range. Reversed bounds or a range
with no levels returns null. Unavailable book data also returns null.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
avgPrice is the quantity-weighted average price of the selected levels.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Ask Range Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let asks = book.askRange(100.0, 110.0)
}data.book.bidsTo
data.book.bidsTo(price: float, barsAgo: int = 0) -> BookSideSummary?Summarizes bid depth from the best price to a chosen price.
Includes bid levels at or above price. A price beyond the far end of the
book includes the whole side. An empty selection or unavailable book data returns
null. avgPrice is the quantity-weighted average of the selected prices.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Bids To Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let bb = book.bestBid()
if bb != null {
let cum = book.bidsTo(bb - 2.0)
}
}data.book.asksTo
data.book.asksTo(price: float, barsAgo: int = 0) -> BookSideSummary?Summarizes ask depth from the best price to a chosen price.
Includes ask levels at or below price. A price beyond the far end of the
book includes the whole side. An empty selection or unavailable book data returns
null. avgPrice is the quantity-weighted average of the selected prices.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Your data plan may limit the levels available to read individually. Built-in summary methods use the full book, so their totals may differ from a loop over the levels available on your plan.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Book Asks To Example"
data chart = subscribe(data.ohlcv)
data book = subscribe(data.book)
on chart.update {
let ba = book.bestAsk()
if ba != null {
let cum = book.asksTo(ba + 2.0)
}
}data.volume.summary
data.volume.summary(barsAgo: int = 0, from: number? = null, to: number? = null) -> VolumeSummary?Summarizes a volume profile, optionally within a price range.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
from and to select prices, including both ends. Null leaves that end
unrestricted, so summary(0) reads the whole current profile. Reversed bounds
or a range with no levels returns null.
Read this from another subscription's handler. Volume profiles have no forming view.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Summary Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let summary = vol.summary(0)
let banded = vol.summary(0, from: 100.0, to: 105.0)
}data.volume.level
data.volume.level(index: int, barsAgo: int = 0) -> VolumeLevel?Reads a volume-profile level by index.
index counts traded price levels from 0, starting with the lowest price.
barsAgo chooses the snapshot. Adjacent levels can be more than one binSize
apart because prices with no stored trades are skipped.
An index beyond the level count, unavailable history, or a missing snapshot
returns null. Read the count with summary(barsAgo).levels.
Contracts
index: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Level Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let s = vol.summary(0)
if s != null {
for i in 0..s.levels {
let lv = vol.level(i)
// lv is non-null for every i in 0..s.levels of the same eval
}
}
}data.volume.time
data.volume.time(barsAgo: int = 0) -> time?Returns the start time of the snapshot period.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Time Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let t = vol.time()
}data.volume.binSize
data.volume.binSize(barsAgo: int = 0) -> float?Returns the width of each price bin.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Bin Size Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let bin = vol.binSize()
}data.volume.numLevels
data.volume.numLevels(barsAgo: int = 0) -> int?Returns the number of traded price levels.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
An empty snapshot returns 0. This matches summary(barsAgo).levels when the
summary is non-null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Num Levels Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let n = vol.numLevels()
}data.volume.total
data.volume.total(barsAgo: int = 0) -> float?Returns the total buy and sell volume.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
An empty snapshot returns 0.0. This matches summary(barsAgo).total when the
summary is non-null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Total Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let tv = vol.total()
}data.volume.delta
data.volume.delta(barsAgo: int = 0) -> float?Returns the buy volume minus sell volume.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
An empty snapshot returns 0.0. This matches summary(barsAgo).delta when the
summary is non-null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Delta Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let dv = vol.delta()
}data.volume.ratio
data.volume.ratio(barsAgo: int = 0) -> float?Returns the volume delta divided by total volume.
barsAgo counts periods on this subscription, with 0 selecting the current
snapshot. An invalid position, a position outside available history, or a missing
snapshot returns null.
Returns NaN if total volume is zero. This matches summary(barsAgo).ratio
when the summary is non-null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Ratio Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let rv = vol.ratio()
}data.volume.poc
data.volume.poc(basis: VolBasis = 0, from: number? = null, to: number? = null, barsAgo: int = 0) -> VolumeLevel?Returns the point of control: the level with the largest selected volume.
basis chooses which volume to compare, defaulting to volbasis.total.
from and to optionally limit the price range, including both ends; null
leaves that end unrestricted. Ties use the lowest price.
barsAgo chooses the snapshot. An empty range, reversed bounds, or a missing
snapshot returns null.
Contracts
barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Poc Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let poc = vol.poc()
let dPoc = vol.poc(basis: volbasis.deltaAbs)
}Accepted values
basis:VolBasisvalues — 4 available.
data.volume.valueArea
data.volume.valueArea(percent: float, basis: VolBasis = 0, from: number? = null, to: number? = null, barsAgo: int = 0) -> VolumeArea?Returns the low and high prices of a volume value area.
percent sets how much of the selected volume the area should cover. basis
chooses the volume to use, defaulting to volbasis.total. from and to
optionally limit the price range; null leaves that end unrestricted.
Starts at the point of control, then adds the neighboring level with more
selected volume until the target percentage is reached. Ties at the point of
control or during expansion choose the lower price. At percent: 100.0, the
area covers the whole range.
lowPrice and highPrice describe the area. The other fields (buy, sell,
total, delta, ratio, and levels) summarize the entire queried price range.
barsAgo chooses the snapshot. An empty range, reversed bounds, or a missing
snapshot returns null.
Contracts
percent: Accepted range: 0.0 to 100.0. Must be a finite number. Invalid values returnnull.barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Volume Value Area Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let va = vol.valueArea(70.0)
}Accepted values
basis:VolBasisvalues — 4 available.
Profile
Volume combined across a rolling window of snapshots.
| Field | Type | History | Description |
|---|
data.volume.profile
data.volume.profile(bars: int) -> ProfileCreates a rolling volume profile over the last bars confirmed snapshots.
Returns a Profile combining the last bars completed volume snapshots
available at the time the handler runs. The profile itself is never null, but
its query results can be null. It has no barsAgo: parameter.
Keep the profile in a let variable or call its methods directly. It cannot
be saved in state, record fields, or collections, passed to a function, or
returned from one.
bars must be known before the script runs: use a literal, input, or
setup value. Invalid bars values are rejected before the script runs.
Each profile supports up to 65,536 distinct price levels and is also subject to the script's resource limits. If either limit is exceeded, its
queries return null without stopping the script. Later queries can remain null
even if the window becomes smaller. Refreshing the data or restarting the
script allows another attempt; reduce bars if the limit keeps being reached.
If fewer than bars completed snapshots are available, the profile uses those
that exist. With no snapshots, all query methods return null.
Contracts
bars: Accepted range: 1 to MAX_ARRAY_LEN. Invalid values are rejected.
Example
script "Data Volume Profile Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let p = vol.profile(bars: 20)
let poc = p.poc()
}data.profile.total
data.profile.total() -> float?Returns the rolling window's total (buy + sell) volume.
Calculates buy + sell across the rolling profile. This matches
summary().total when the summary is non-null. A window with no snapshots
returns null.
With one snapshot, profile(bars: 1).total() equals vol.total(). Unavailable
profile data also returns null.
Example
script "Data Profile Total Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let t = vol.profile(bars: 20).total()
}data.profile.delta
data.profile.delta() -> float?Returns the rolling window's volume delta (buy - sell).
Calculates buy - sell across the rolling profile. This matches
summary().delta when the summary is non-null. A window with no snapshots
returns null.
Example
script "Data Profile Delta Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let d = vol.profile(bars: 20).delta()
}data.profile.ratio
data.profile.ratio() -> float?Returns the rolling window's volume-delta ratio (delta / total).
Calculates delta / total across the rolling profile. This matches
summary().ratio when the summary is non-null. A window with no snapshots
returns null. A zero total volume gives NaN.
Example
script "Data Profile Ratio Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let r = vol.profile(bars: 20).ratio()
}data.profile.summary
data.profile.summary(from: number? = null, to: number? = null) -> VolumeSummary?Summarizes a rolling profile, optionally within a price range.
from and to select prices, including both ends. Null leaves that end
unrestricted. An empty range, reversed bounds, or a window with no snapshots
returns null.
time is the start time of the newest snapshot period. binSize is the finest
price-bin size in the window. levels counts distinct combined price levels
within the selected range.
Example
script "Data Profile Summary Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let p = vol.profile(bars: 20)
let banded = p.summary(from: 100.0, to: 105.0)
}data.profile.poc
data.profile.poc(basis: VolBasis = 0, from: number? = null, to: number? = null) -> VolumeLevel?Returns the point of control: the level with the largest selected volume.
basis chooses which volume to compare, defaulting to volbasis.total.
from and to optionally limit the price range, including both ends; null
leaves that end unrestricted. Ties use the lowest price.
Returns the combined level's price, buy, sell, total, delta, and ratio. Its
index is -1 because it does not belong to one snapshot. An empty range or
a window with no snapshots returns null.
Example
script "Data Profile Poc Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let poc = vol.profile(bars: 20).poc(basis: volbasis.deltaAbs)
}Accepted values
basis:VolBasisvalues — 4 available.
data.profile.valueArea
data.profile.valueArea(percent: float, basis: VolBasis = 0, from: number? = null, to: number? = null) -> VolumeArea?Returns the low and high prices of a volume value area.
percent sets how much of the selected volume the area should cover. basis
chooses the volume to use, defaulting to volbasis.total. from and to
optionally limit the price range; null leaves that end unrestricted.
Starts at the point of control, then adds the neighboring level with more
selected volume until the target percentage is reached. Ties at the point of
control or during expansion choose the lower price. At percent: 100.0, the
area covers the whole range.
lowPrice and highPrice describe the area. The other fields (buy, sell,
total, delta, ratio, and levels) summarize the entire queried price range.
An empty range or a window with no snapshots returns null.
Contracts
percent: Accepted range: 0.0 to 100.0. Must be a finite number. Invalid values returnnull.
Example
script "Data Profile Value Area Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let va = vol.profile(bars: 20).valueArea(70.0)
}Accepted values
basis:VolBasisvalues — 4 available.
data.profile.buckets
data.profile.buckets(count: int, from: number? = null, to: number? = null) -> VolumeBuckets?Groups volume into equal-width price buckets.
count chooses the number of buckets. They span from the lowest selected
price through one binSize above the highest. Each level goes into the bucket
containing its price, so bucket totals add up to the selected range's totals.
A count below 1 or above 4096 returns null.
from and to select the price range first, including both ends. Null leaves
that end unrestricted. An empty range or reversed bounds returns null.
A window with no snapshots returns null. The profile combines volume at each
price before grouping it.
Read the values you need before calling buckets or bucketsByLevels again
during the same calculation step. A later call replaces the data read through
earlier bucket views, even on another snapshot or profile. Request the buckets
again when you need a fresh view.
Contracts
count: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Profile Buckets Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let b = vol.profile(bars: 20).buckets(4)
if b != null {
for bkt in b {
// bkt.total over [bkt.from, bkt.to)
}
}
}data.profile.bucketsByLevels
data.profile.bucketsByLevels(levelsPerBucket: int, from: number? = null, to: number? = null) -> VolumeBuckets?Groups consecutive price levels into volume buckets.
levelsPerBucket chooses how many levels to put in each bucket. The last bucket
can contain fewer levels. Each bucket starts at its first level's price and
ends one binSize above its last level. A value below 1 returns null. The result cannot exceed 4096 buckets;
exceeding that limit returns null.
from and to select the price range first, including both ends. Null leaves
that end unrestricted. An empty range or reversed bounds returns null.
A window with no snapshots returns null. The profile combines volume at each
price before grouping it.
Read the values you need before calling buckets or bucketsByLevels again
during the same calculation step. A later call replaces the data read through
earlier bucket views, even on another snapshot or profile. Request the buckets
again when you need a fresh view.
Contracts
levelsPerBucket: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values returnnull.
Example
script "Data Profile Buckets By Levels Example"
data chart = subscribe(data.ohlcv)
data vol = subscribe(data.volume)
on chart.update {
let b = vol.profile(bars: 20).bucketsByLevels(8)
if b != null {
let first = b.get(0)
}
}bookunit.base
bookunit.base: BookUnit = 1Selects base quantity for book imbalance calculations.
bookunit.quote
bookunit.quote: BookUnit = 2Selects quote value for book imbalance calculations.
volbasis.total
volbasis.total: VolBasis = 0Ranks profile levels by total (buy + sell) volume.
volbasis.buy
volbasis.buy: VolBasis = 1Ranks profile levels by buy volume.
volbasis.sell
volbasis.sell: VolBasis = 2Ranks profile levels by sell volume.
volbasis.deltaAbs
volbasis.deltaAbs: VolBasis = 3Ranks profile levels by |buy - sell| (absolute per-level delta).
data.trades
source data.trades -> TradesSubDelivers individual trades to a trade handler.
exchangeandsymbolchoose the market. Null inherits the chart's market, the window's market, or the run settings when neither is present.minSizekeeps only trades withsize >= minSize. Null applies no size filter. A non-positive or non-finite value is rejected before the subscription starts.historyrequests earlier trades as a duration. Null uses the default; your data plan may cap the requested history. When every trades subscription on the market sets a positivehistory, only that much is loaded, however long the chart's range is. Zero (0sortime.seconds(0)) asks for live trades only: no earlier trades are loaded and the trade handler runs only for trades that arrive after the script goes live, not for earlier trades of the current bar. A negative constant is an error.
Contracts
minSize: Accepted range: greater than 0.0. Must be a finite number. Invalid values are rejected.
Example
script "Data Trades Example"
data tape = subscribe(data.trades, minSize: 1.0)
on tape.trade(tr) {
let price = tr.price
}TradesSub
Delivers trades through on sub.trade(tr); trades cannot be read as subscription fields.
| Field | Type | History | Description |
|---|
Trade
Single trade-tape event, delivered to on sub.trade.
| Field | Type | History | Description |
|---|---|---|---|
time | time | false | Trade timestamp in Unix seconds, rounded down to a whole second. |
price | float | false | Trade price. |
size | float | false | Trade size, always positive. |
isBuy | bool | false | true = aggressive buy, false = aggressive sell. |
open
Runs once when a new bar opens.
Runs before any updates for the new bar. The previous bar is already confirmed and available in history.
update
Runs on each update while the current bar is forming.
Runs after the bar opens and before it closes. The forming values include the latest update.
close
Runs once when a bar closes and becomes confirmed.
The bar values are final and the bar is now available in history.
trade
Runs once for each trade delivered by the subscription.
The handler argument contains the trade's price, size, side, and time.