MMTMMT Docs
Built-in catalog

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

ValueMeaning
bookunit.baseSelects base quantity for book imbalance calculations.
bookunit.quoteSelects quote value for book imbalance calculations.

VolBasis

ValueMeaning
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 -> OhlcvSub

Subscribes to price and volume bars.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0, 0s, or time.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 its isHistory reads 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 .forming read 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 -> OiSub

Subscribes to open interest bars.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0, 0s, or time.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 its isHistory reads 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 -> VdSub

Subscribes to volume delta bars.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0, 0s, or time.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 its isHistory reads 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.
  • bucket selects 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 -> CvdSub

Subscribes to cumulative volume delta bars.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0, 0s, or time.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 its isHistory reads 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.
  • bucket selects 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 -> StatSub

Subscribes to market statistics bars.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0, 0s, or time.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 its isHistory reads 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 -> BookSub

Provides order-book snapshots to read from another subscription's handler.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0 or 0s) 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 -> VolumeSub

Provides volume-profile snapshots to read from another subscription's handler.

  • exchange, symbol, and timeframe choose 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.
  • history requests earlier data as a number of source periods or a duration. Null uses the default. Zero (0 or 0s) 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.

FieldTypeHistoryDescription
timetime?trueOpening time of the confirmed bar. [n] looks back by this subscription's periods.
openfloat?trueConfirmed open price.
highfloat?trueConfirmed high price.
lowfloat?trueConfirmed low price.
closefloat?trueConfirmed close price.
volumefloat?trueConfirmed total volume.
buyVolumefloat?trueConfirmed buy volume.
sellVolumefloat?trueConfirmed sell volume.
buyCountint?trueConfirmed buy trade count.
sellCountint?trueConfirmed sell trade count.
tradesint?trueConfirmed trade count.
formingOhlcvFormingfalseCurrent forming OHLCV values. Read these values directly; history indexing with [n] is not supported.
isNewboolfalseTrue during an update in which this subscription confirmed at least one period.
isRealtimeboolfalseTrue while the forming period receives live updates.
isHistoryboolfalseTrue during history replay.
isFirstboolfalseTrue when index == 0.
indexintfalsePosition of the current reference period in the loaded history, counting from 0.
isLastboolfalseTrue 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.

FieldTypeHistoryDescription
timetime?falseOpening time of the forming bar.
openfloat?falseForming open price.
highfloat?falseForming high price.
lowfloat?falseForming low price.
closefloat?falseForming close price.
volumefloat?falseForming total volume.
buyVolumefloat?falseForming buy volume.
sellVolumefloat?falseForming sell volume.
buyCountint?falseForming buy trade count.
sellCountint?falseForming sell trade count.
tradesint?falseForming trade count.

OiSub

Open-interest subscription record.

FieldTypeHistoryDescription
timetime?trueOpening time of the confirmed bar.
openfloat?trueConfirmed open-interest open value.
highfloat?trueConfirmed open-interest high value.
lowfloat?trueConfirmed open-interest low value.
closefloat?trueConfirmed open-interest close value.
formingOiFormingfalseCurrent forming open-interest values. Read these values directly; history indexing with [n] is not supported.
isNewboolfalseTrue during an update in which this subscription confirmed at least one period.
isRealtimeboolfalseTrue while the forming period receives live updates.
isHistoryboolfalseTrue during history replay.
isFirstboolfalseTrue when index == 0.
indexintfalsePosition of the current reference period in the loaded history, counting from 0.
isLastboolfalseTrue 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.

FieldTypeHistoryDescription
timetime?falseOpening time of the forming bar.
openfloat?falseForming open-interest open value.
highfloat?falseForming open-interest high value.
lowfloat?falseForming open-interest low value.
closefloat?falseForming open-interest close value.

VdSub

Volume-delta subscription record.

FieldTypeHistoryDescription
timetime?trueOpening time of the confirmed bar.
openfloat?trueConfirmed volume-delta open value.
highfloat?trueConfirmed volume-delta high value.
lowfloat?trueConfirmed volume-delta low value.
closefloat?trueConfirmed volume-delta close value.
bucketintfalseVolume-delta bucket group.
bucketLabelstringfalseVolume-delta bucket label.
bucketMinUsdfloat?falseVolume-delta bucket minimum USD notional.
bucketMaxUsdfloat?falseVolume-delta bucket maximum USD notional.
formingVdFormingfalseCurrent forming volume-delta values. Read these values directly; history indexing with [n] is not supported.
isNewboolfalseTrue during an update in which this subscription confirmed at least one period.
isRealtimeboolfalseTrue while the forming period receives live updates.
isHistoryboolfalseTrue during history replay.
isFirstboolfalseTrue when index == 0.
indexintfalsePosition of the current reference period in the loaded history, counting from 0.
isLastboolfalseTrue 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.

FieldTypeHistoryDescription
timetime?falseOpening time of the forming bar.
openfloat?falseForming volume-delta open value.
highfloat?falseForming volume-delta high value.
lowfloat?falseForming volume-delta low value.
closefloat?falseForming volume-delta close value.
bucketintfalseVolume-delta bucket group.
bucketLabelstringfalseVolume-delta bucket label.
bucketMinUsdfloat?falseVolume-delta bucket minimum USD notional.
bucketMaxUsdfloat?falseVolume-delta bucket maximum USD notional.

CvdSub

Cumulative volume-delta data for this script run.

FieldTypeHistoryDescription
timetime?trueOpening time of the confirmed bar.
openfloat?trueConfirmed cumulative volume-delta open value.
highfloat?trueConfirmed cumulative volume-delta high value.
lowfloat?trueConfirmed cumulative volume-delta low value.
closefloat?trueConfirmed cumulative volume-delta close value.
bucketintfalseCVD bucket group.
bucketLabelstringfalseCVD bucket label.
bucketMinUsdfloat?falseCVD bucket minimum USD notional.
bucketMaxUsdfloat?falseCVD bucket maximum USD notional.
formingCvdFormingfalseCurrent forming CVD values. Read these values directly; history indexing with [n] is not supported.
isNewboolfalseTrue during an update in which this subscription confirmed at least one period.
isRealtimeboolfalseTrue while the forming period receives live updates.
isHistoryboolfalseTrue during history replay.
isFirstboolfalseTrue when index == 0.
indexintfalsePosition of the current reference period in the loaded history, counting from 0.
isLastboolfalseTrue 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.

FieldTypeHistoryDescription
timetime?falseOpening time of the forming bar.
openfloat?falseForming cumulative volume-delta open value.
highfloat?falseForming cumulative volume-delta high value.
lowfloat?falseForming cumulative volume-delta low value.
closefloat?falseForming cumulative volume-delta close value.
bucketintfalseCVD bucket group.
bucketLabelstringfalseCVD bucket label.
bucketMinUsdfloat?falseCVD bucket minimum USD notional.
bucketMaxUsdfloat?falseCVD bucket maximum USD notional.

StatSub

Market-statistics subscription record.

FieldTypeHistoryDescription
timetime?trueOpening time of the confirmed statistics bar.
sellLiqfloat?trueConfirmed sell liquidation value.
buyLiqfloat?trueConfirmed buy liquidation value.
markPricefloat?trueConfirmed mark price. Null when the feed carries no mark; aggregate exchange specs never have one.
fundingRatefloat?trueConfirmed funding rate.
formingStatFormingfalseCurrent last-value statistics view. Read these values directly; history indexing with [n] is not supported.
isNewboolfalseTrue during an update in which this subscription confirmed at least one period.
isRealtimeboolfalseTrue while the forming period receives live updates.
isHistoryboolfalseTrue during history replay.
isFirstboolfalseTrue when index == 0.
indexintfalsePosition of the current reference period in the loaded history, counting from 0.
isLastboolfalseTrue 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.

FieldTypeHistoryDescription
timetime?falseOpening time of the forming statistics bar.
sellLiqfloat?falseLast-value sell liquidation value.
buyLiqfloat?falseLast-value buy liquidation value.
markPricefloat?falseLast-value mark price. Null when the feed carries no mark; aggregate exchange specs never have one.
fundingRatefloat?falseLast-value funding rate.

BookSub

Order-book snapshots read through subscription methods.

FieldTypeHistoryDescription

VolumeSub

Volume-profile snapshots read through subscription methods.

FieldTypeHistoryDescription

BookDepth

Describes order-book depth over a price band.

FieldTypeHistoryDescription
timetimefalseStart time of the snapshot period.
binSizefloatfalseBook price-bin size.
bidQtyfloatfalseBid quantity in the query range.
askQtyfloatfalseAsk quantity in the query range.
bidValuefloatfalseBid quote value in the query range.
askValuefloatfalseAsk quote value in the query range.
bidLevelsintfalseBid levels included in the query range.
askLevelsintfalseAsk levels included in the query range.
bidMinPricefloat?falseLowest bid price included, or null when empty.
bidMaxPricefloat?falseHighest bid price included, or null when empty.
askMinPricefloat?falseLowest ask price included, or null when empty.
askMaxPricefloat?falseHighest ask price included, or null when empty.
deltaQtyfloatfalseBid quantity minus ask quantity.
deltaValuefloatfalseBid value minus ask value.
totalQtyfloatfalseBid plus ask quantity.
totalValuefloatfalseBid plus ask value.
ratioQtyfloatfalseQuantity imbalance ratio; NaN when total quantity is 0.
ratioValuefloatfalseValue imbalance ratio; NaN when total value is 0.
ratiofloatfalseDefault quote-value imbalance ratio; NaN when total value is 0.

VolumeSummary

Summarizes a volume-profile snapshot.

FieldTypeHistoryDescription
timetimefalseStart time of the snapshot period.
binSizefloatfalseVolume-profile price-bin size.
levelsintfalseNumber of profile levels included.
minPricefloatfalseLowest profile price included.
maxPricefloatfalseHighest profile price included.
buyfloatfalseBuy volume.
sellfloatfalseSell volume.
totalfloatfalseTotal volume.
deltafloatfalseBuy volume minus sell volume.
ratiofloatfalseVolume-delta ratio; NaN when total volume is 0.

VolumeLevel

Represents one volume-profile level.

FieldTypeHistoryDescription
timetimefalseStart time of the snapshot period.
binSizefloatfalseVolume-profile price-bin size.
indexintfalse0-based level index, ascending by price.
pricefloatfalseLevel price.
buyfloatfalseBuy volume at this level.
sellfloatfalseSell volume at this level.
totalfloatfalseBuy plus sell volume.
deltafloatfalseBuy volume minus sell volume.
ratiofloatfalseVolume-delta ratio; NaN when total volume is 0.

BookLevel

One order-book price level.

FieldTypeHistoryDescription
indexintfalse0-based level index within the side, 0 = best.
pricefloatfalseLevel price.
qtyfloatfalseLevel quantity.
valuefloatfalseTotal value at this level: price * qty.

FootprintBucket

One price bucket containing grouped volume.

FieldTypeHistoryDescription
indexintfalse0-based bucket index, ascending by price.
fromfloatfalseInclusive lower price bound of the bucket.
tofloatfalseExclusive upper price bound of the bucket.
buyfloatfalseBuy volume re-binned into the bucket.
sellfloatfalseSell volume re-binned into the bucket.
totalfloatfalseTotal volume: buy + sell.
deltafloatfalseVolume delta: buy - sell.

BookLevels

Price levels on one side of the order book.

FieldTypeHistoryDescription
lenintfalseNumber of levels in the view; raw depth may be capped by your data plan.
timetimefalseStart time of the snapshot period.
binSizefloatfalseBook price-bin size.

VolumeLevels

Price levels in a volume profile.

FieldTypeHistoryDescription
lenintfalseNumber of stored profile levels in the view.
timetimefalseStart time of the snapshot period.
binSizefloatfalseVolume-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.

FieldTypeHistoryDescription
lenintfalseNumber of buckets in the view.
timetimefalseStart time of the snapshot period.
binSizefloatfalseFinest 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 return null.

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 return null.

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 return null.

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 return null.
  • barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values return null.

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 return null.
  • barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values return null.

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 return null.

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 return null.

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 return null.

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 return null.

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.

FieldTypeHistoryDescription
timetimefalseStart time of the snapshot period.
binSizefloatfalseBook price-bin size.
levelsintfalseLevels included in the band.
qtyfloatfalseTotal quantity in the band.
valuefloatfalseTotal quote value, summed as price times quantity in the band.
avgPricefloatfalseQuantity-weighted average price of the band (ladder VWAP): value / qty.
minPricefloatfalseLowest level price included.
maxPricefloatfalseHighest level price included.

VolumeArea

Describes a volume-profile value area.

FieldTypeHistoryDescription
pocPricefloatfalsePrice with the largest value for the selected basis. Ties use the lowest price.
lowPricefloatfalseValue-area low (VAL).
highPricefloatfalseValue-area high (VAH).
buyfloatfalseBuy volume over the queried band.
sellfloatfalseSell volume over the queried band.
totalfloatfalseTotal volume over the queried band.
deltafloatfalseBuy minus sell volume over the queried band.
ratiofloatfalseVolume-delta ratio over the queried band (NaN when total is 0).
levelsintfalseDistinct 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.

  • outerPct sets the distance on either side of ref, as a percentage: from ref * (1 - outerPct/100) to ref * (1 + outerPct/100). Values outside its allowed range stop the script with an error.
  • ref defaults to the mid price. Without both a bid and an ask, the default reference is unavailable and the result is null.
  • innerPct optionally 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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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.

  • outerPct sets the price band, as for depth. Values outside its allowed range stop the script with an error.
  • unit chooses quote value (bookunit.quote, the default) or base quantity (bookunit.base).
  • ref defaults to the mid price. innerPct defaults 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 return null.

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

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.
  • barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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 return null.

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

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 return null.
  • barsAgo: Accepted range: 0 to MAX_ARRAY_LEN. Invalid values return null.

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

Profile

Volume combined across a rolling window of snapshots.

FieldTypeHistoryDescription

data.volume.profile

data.volume.profile(bars: int) -> Profile

Creates 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

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 return null.

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

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 return null.

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 return null.

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 = 1

Selects base quantity for book imbalance calculations.

bookunit.quote

bookunit.quote: BookUnit = 2

Selects quote value for book imbalance calculations.

volbasis.total

volbasis.total: VolBasis = 0

Ranks profile levels by total (buy + sell) volume.

volbasis.buy

volbasis.buy: VolBasis = 1

Ranks profile levels by buy volume.

volbasis.sell

volbasis.sell: VolBasis = 2

Ranks profile levels by sell volume.

volbasis.deltaAbs

volbasis.deltaAbs: VolBasis = 3

Ranks profile levels by |buy - sell| (absolute per-level delta).

data.trades

source data.trades -> TradesSub

Delivers individual trades to a trade handler.

  • exchange and symbol choose the market. Null inherits the chart's market, the window's market, or the run settings when neither is present.
  • minSize keeps only trades with size >= minSize. Null applies no size filter. A non-positive or non-finite value is rejected before the subscription starts.
  • history requests 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 positive history, only that much is loaded, however long the chart's range is. Zero (0s or time.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.

FieldTypeHistoryDescription

Trade

Single trade-tape event, delivered to on sub.trade.

FieldTypeHistoryDescription
timetimefalseTrade timestamp in Unix seconds, rounded down to a whole second.
pricefloatfalseTrade price.
sizefloatfalseTrade size, always positive.
isBuyboolfalsetrue = 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.

On this page