Guides

Market data

This page lists what a script can read about the market, apart from the order-by-order feed and the book, which are covered in Order flow.

Bars#

The body of a script runs once per bar, after every event of that bar.

NameTypeMeaning
open, high, low, close, volume (also bar.open … bar.volume)numberThe bar's values. Inside handlers and patterns: the bar so far, built trade by trade up to the event. Before the bar's first trade they hold the previous close (na on the very first bar), and volume is 0.
delta (also bar.delta)number or naBuy volume minus sell volume, by aggressor side. na when the source gives no aggressor side.
bar.buy_volume, bar.sell_volumenumber or na(volume + delta) / 2 and (volume − delta) / 2.
bar.delta_high, bar.delta_lownumber or naHighest and lowest running delta inside the bar, when known. Always na inside handlers.
bar.timetimeThe bar's open time.
bar.close_timetimeTime bars: open + timeframe. Other bar types: the open of the next bar.
bar.indexnumber0 for the first bar the script received.
bar.lastboolThe last bar received.
bar.confirmedboolFalse on a bar that is still forming (see The language).
bar.gapboolTrue after a real gap in the data.
bar.hour, bar.minute, bar.dayofweeknumberNew York time of the bar's open. dayofweek: 1 = Monday … 7 = Sunday.
event.timetimeIn a handler, pattern or clock: the time of the event being processed. In the body: the bar's open.
now()timeIn a handler: the event's time. On a closed bar: its close. On the bar forming: the time of the latest data.

All bar series accept history: close[1], volume[3], bar.time[1].

How many bars. An indicator receives the chart's last 2,000 bars. So does a strategy or research script that reads the footprint. Any other strategy or research script gets a window whose start is fixed when it is launched: all the chart's bars if there are 8,000 or fewer, otherwise the last 4,000 to 8,000 (the start is rounded to a multiple of 4,000 bars). From then on the window keeps that start and grows with each new bar, up to 48,000 bars; beyond that its start moves forward by 8,000 bars, and the Report says what is no longer simulated. A script never receives more than 50,000 bars (E945).

StrateScript
indicator "Bar fields" { overlay: false }
plot(delta, title: "Delta")
plot(bar.buy_volume - bar.sell_volume, title: "Check")
plot(nz(bar.delta_high), title: "Delta high")
print(bar.index, str(bar.time, "HH:mm"), str(bar.close_time, "HH:mm"), bar.confirmed, bar.last, bar.gap, bar.hour, bar.minute, bar.dayofweek)

The chart and the instrument#

NameMeaning
chart.timeframeThe chart's unit as text: "5s", "1m", "1h", "1d", "1w", "8r" (range), "4k" (renko), "500v" (volume), "300delta", "100t" (tick), "3x" (reversal). na if unknown. Inside request(tf, …) it is tf.
chart.timeframe_secondsLength of a time bar in seconds; 0 for other bar types.
chart.bar_type"time", "range", "renko", "volume", "delta", "tick" or "reversal".
chart.tick_px, chart.bar_pxHeight of one tick and width of one bar on screen, in pixels (by steps of 5 px).
chart.row_ticks(min_px = 14)A round number of ticks per row such that a row is at least min_px pixels high at the current zoom (1, 2, 4, 5, 8, 10, 16, 20, 25…). 1 when the zoom is unknown.
chart.columns(min_px = 30)How many columns of at least min_px pixels fit in one bar at the current zoom (at least 1).
instrument.tickMinimum price increment (0.25 on ES).
instrument.symbolThe symbol, e.g. "ES".
instrument.point_valueValue of one point in USD (50 on ES).

Footprint#

bar.footprint is the bar's volume at each price, split by aggressor side. Read it in the body:

Text
fp = bar.footprint

Reading bar.footprint inside a handler, a pattern or a clock gives E911: the footprint describes the whole bar, which is not finished yet at that moment.

Footprint fields

FieldMeaning
availableFalse when the bar has no trade data.
levelsList of price levels, lowest price first.
pocPrice with the most volume.
high, lowHighest and lowest traded price.
volume, delta, buy, sell, tradesTotals over the bar.
stepRow height in price.
buy_trades, sell_trades, max_trade, max_buy, max_sell, avg_trade, avg_buy, avg_sell, first_time, last_timePer-trade detail; na when the source has no per-trade detail.

Footprint methods

MethodReturns
fp.level(price)The level at that price, or na. Reading a field of na gives na.
fp.value_area(pct = 70)An object with .high, .low, .poc, or na.
fp.rows(ticks)The same footprint with rows of ticks ticks (whole number ≥ 1, else E935).
fp.imbalances(side, ratio: 3, min_volume: 0)List of prices where side ("buy" or "sell", else E933) has at least max(min_volume, 1) and at least ratio times the volume on the diagonal.
fp.stacked(side, ratio: 3, count: 3)List of [low, high] zones where at least count (minimum 2) consecutive imbalances stack.

Level fields: price, buy, sell, volume, delta, trades, and the same per-trade detail fields as the footprint.

Accumulating several bars. footprint.accumulator() creates a profile you feed bar by bar: acc.add(bar.footprint) (a value that is not a footprint gives E934; na is ignored), acc.reset(), acc.bars (bars added). It has the same fields and methods as a footprint, with a step of one tick.

StrateScript
indicator "Footprint read" { overlay: true }
fp = bar.footprint
va = fp.value_area(70)
plot(nz(fp.poc), #e8c15a, title: "POC", style: "circles")
plot(va.high, #2962ff, title: "VA high")
plot(va.low, #2962ff, title: "VA low")
for p in fp.imbalances("buy", ratio: 3) { cell(p, "B", side: right, color: #26a69a, size: 9) }
for p in fp.imbalances("sell", ratio: 3) { cell(p, "S", side: left, color: #ef5350, size: 9) }
for z in fp.stacked("buy", ratio: 3, count: 3) { draw.rect(z[0], z[1], x: 0, w: 1, fill: #26a69a30) }
StrateScript
indicator "Session profile POC" { overlay: true }
var prof = footprint.accumulator()
if session.is_new { prof.reset() }
prof.add(bar.footprint)
plot(nz(prof.poc), #e8c15a, title: "Session POC")

Sessions, hours and the previous day#

Times are New York time (US daylight saving included). The CME session runs from 18:00 to 17:00 the next day; regular trading hours (RTH) run from 9:30 to 16:00.

NameMeaning
session.is_newFirst bar of a CME session (also true on the first bar received).
session.is_new_dayFirst bar of a new New York date.
session.is_last_barLast bar of a CME session among the bars received (also true on the last bar received).
session.rthThe bar opens within 9:30–16:00.
session.dayNumber of the CME session's trading date (days since 1970-01-01).
session.high, session.lowSince 18:00.
session.overnight_high, session.overnight_low18:00 to 9:30, then frozen.
session.rth_high, session.rth_lowSince 9:30.
session.ib_high, session.ib_lowInitial balance: from 9:30 for the length set by the header key initial_balance: (default 60m).
prev.high, prev.low, prev.closeThe last complete RTH session before the current one. na if that session was shortened or has a gap.

The levels are built from the instrument's one-minute bars, whatever the chart's unit, and never use data after the current bar's close (or after the event, in a handler). A minute counts in a period only if it lies entirely inside it. A level is na when the start of its period is missing. There is no settlement price.

Time ranges. session.in(range) tells whether the bar's open is inside a range, and session.in(range, time) tests another instant (for example event.time):

An invalid range gives E925. input.session(title, default) lets the user edit a range in the Settings tab.

Session events. on session(s) runs at each boundary: s.kind is "session_open" (18:00), "rth_open", "rth_close" or "session_close" (17:00); s.time is the time of the first event or bar after the boundary; s.rth and s.day are also available. Boundaries crossed at the same time arrive in order.

StrateScript
indicator "Session levels" { overlay: true, initial_balance: 30m }
plot(session.overnight_high, #8888ff, title: "ON high")
plot(session.overnight_low, #8888ff, title: "ON low")
plot(session.ib_high, #e8c15a, title: "IB high")
plot(session.ib_low, #e8c15a, title: "IB low")
plot(prev.close, #ffffff80, title: "Prev close", style: "dashed")
bg_color(session.in("0930-1030") ? #ffffff08 : na)
StrateScript
indicator "Session events" { overlay: true }
on session(s) { label.new(s.time, close, s.kind) }
plot(close, title: "Close")

Other timeframes and other instruments: request#

Text
request(tf, expr)
request(expr, symbol: "NQ")
request(tf, expr, symbol: "NQ")

request evaluates expr on another series of bars and returns its value from the last bar of that series that has closed at or before the current bar's close. Until one has closed, it returns na. It never looks ahead.

StrateScript
indicator "Higher timeframes" { overlay: true }
plot(request("5m", ema(close, 20)), #e8c15a, title: "5m EMA 20")
plot(request(15m, close), #2962ff, title: "15m close", style: "step")
plot(request("1d", high), #ffffff60, title: "Day high")

A script that uses symbol: cannot pass the built-in check, because the check's synthetic market has no other instrument: it reports E936. Such a script runs on a chart where Strate has bars for that symbol. For example, nq = request(close, symbol: "NQ") reads the last closed one-minute close of NQ.

Trades one by one: on trade#

Text
on trade(t) { … }

The handler runs for every trade, in exchange order. All trades of a bar run before the bar's body, and each call has its own budget.

FieldMeaning
t.timeTime of the trade.
t.price, t.sizePrice and size.
t.side"buy" (buyer was the aggressor), "sell", or na if unknown.
t.deltaSigned size: +size for a buy, −size for a sell.
t.is_buy, t.is_sellBools.

With order-by-order data, each trade is one execution of one aggressive order at one price, and these fields are also filled (they are na otherwise, so test na(t.levels)):

FieldMeaning
t.sweepTotal size of that aggressive order across all the prices it traded.
t.levelsNumber of distinct prices the aggressive order traded.
t.sweep_start, t.sweep_endTrue on the first / last execution of the aggressive order. Test t.sweep_end to act once per order.
t.aggressor_idId of the aggressive order (na when the feed gives none).
t.passive_idFirst resting order hit at this price.
t.passive_countNumber of resting orders hit at this price.

Executions are grouped into one aggressive order when they share the same exchange timestamp, the same side and the same aggressor id (or an unknown id). Trades from before the start of the order-by-order window come from the plain trade record, and their sweep fields are na.

StrateScript
indicator "Sweeps" { overlay: true }
minLevels = input.int("Min levels", 2, min: 1)
on trade(t) {
  if not na(t.levels) and t.sweep_end and t.levels >= minLevels {
    label.new(t.time, t.price, (t.is_buy ? "buy sweep " : "sell sweep ") + str(t.sweep), color: t.is_buy ? #26a69a : #ef5350)
  }
}
plot(close, title: "Close")

A handler that accumulates per bar keeps its total in a state variable, and the body resets it after using it:

StrateScript
indicator "Large-print volume" { overlay: false }
minSize = input.int("Min size", 20, min: 1)
state big = 0
on trade(t) {
  if t.size >= minSize { big += t.delta }
}
histogram(big, big >= 0 ? #26a69a : #ef5350, title: "Signed large prints")
big = 0

Where the data comes from: live, Replay, long backtest#

DataReplay of a recorded session (MBO replay files)LiveLong backtest (local MBO replay files)
Bars (OHLCV, delta)yesyesbuilt from the file's trades (time bars only)
Footprintyesyesna
Trades (on trade)yesyesyes, real executions
Sweep fields (t.sweep…)yes, inside the order-by-order windowyes, inside Strate's MBO recordingyes
Book snapshots (on book, book.*)yes, every 250 msyes, every 250 msna
Order by order (on order, on match, mbo.*, of.ofi)yes, exactly as in the filesyes, from Strate's own MBO recordingyes
Session levels (session.*, prev.*)yesyesyes (previous days of the same contract)
request(…, symbol:)if that symbol's one-minute bars exist for the replayed periodyesna

A quick way to see what a chart provides:

StrateScript
indicator "Data check" { overlay: false }
print("mbo", mbo.available, "book", book.available, "footprint", bar.footprint.available)
plot(mbo.available ? 1 : 0, title: "MBO")

How Strate decides what to load#

Trades, book snapshots, footprints and the order-by-order feed are only loaded for a script that uses them. Strate decides by reading the script's text. Line comments (// …) are ignored; a /* … */ comment is not, so a word such as footprint or on trade inside it still loads the data:

DataLoaded when the text contains
Tradeson trade, a strategy header, on: trade or on: level, a clock (clock.time(, clock.volume(, clock.trades(, clock.range(, clock.events(), or of.flow(, of.trade_count(, of.aggression(, of.decay(, of.burst(, of.vpin(
Book snapshotson book, on: book, or the word book
Footprintthe word footprint
Order by orderon order, on match, on: order, on: match, mbo., fill_model: queue, .sweep, .sweep_start, .sweep_end, .aggressor_id, .passive_id, .passive_count, of.ofi(, or on trade together with .levels

This table is for scripts on a chart. A long backtest reads its trades from the replay files and rebuilds the order-by-order book only for a script whose text (or that of a script it imports) contains on order, on match, mbo. or of.ofi(.

Two consequences:

STRATE / PRODUCT SCREENSHOT

Actual platform screenshot.