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 chart and the instrument
- Footprint
- Sessions, hours and the previous day
- Other timeframes and other instruments:
request - Trades one by one:
on trade - Where the data comes from: live, Replay, long backtest
- How Strate decides what to load
Bars#
The body of a script runs once per bar, after every event of that bar.
| Name | Type | Meaning |
|---|---|---|
open, high, low, close, volume (also bar.open … bar.volume) | number | The 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 na | Buy volume minus sell volume, by aggressor side. na when the source gives no aggressor side. |
bar.buy_volume, bar.sell_volume | number or na | (volume + delta) / 2 and (volume − delta) / 2. |
bar.delta_high, bar.delta_low | number or na | Highest and lowest running delta inside the bar, when known. Always na inside handlers. |
bar.time | time | The bar's open time. |
bar.close_time | time | Time bars: open + timeframe. Other bar types: the open of the next bar. |
bar.index | number | 0 for the first bar the script received. |
bar.last | bool | The last bar received. |
bar.confirmed | bool | False on a bar that is still forming (see The language). |
bar.gap | bool | True after a real gap in the data. |
bar.hour, bar.minute, bar.dayofweek | number | New York time of the bar's open. dayofweek: 1 = Monday … 7 = Sunday. |
event.time | time | In a handler, pattern or clock: the time of the event being processed. In the body: the bar's open. |
now() | time | In 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).
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#
| Name | Meaning |
|---|---|
chart.timeframe | The 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_seconds | Length 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_px | Height 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.tick | Minimum price increment (0.25 on ES). |
instrument.symbol | The symbol, e.g. "ES". |
instrument.point_value | Value 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:
fp = bar.footprintReading 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
| Field | Meaning |
|---|---|
available | False when the bar has no trade data. |
levels | List of price levels, lowest price first. |
poc | Price with the most volume. |
high, low | Highest and lowest traded price. |
volume, delta, buy, sell, trades | Totals over the bar. |
step | Row height in price. |
buy_trades, sell_trades, max_trade, max_buy, max_sell, avg_trade, avg_buy, avg_sell, first_time, last_time | Per-trade detail; na when the source has no per-trade detail. |
Footprint methods
| Method | Returns |
|---|---|
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.
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) }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.
| Name | Meaning |
|---|---|
session.is_new | First bar of a CME session (also true on the first bar received). |
session.is_new_day | First bar of a new New York date. |
session.is_last_bar | Last bar of a CME session among the bars received (also true on the last bar received). |
session.rth | The bar opens within 9:30–16:00. |
session.day | Number of the CME session's trading date (days since 1970-01-01). |
session.high, session.low | Since 18:00. |
session.overnight_high, session.overnight_low | 18:00 to 9:30, then frozen. |
session.rth_high, session.rth_low | Since 9:30. |
session.ib_high, session.ib_low | Initial balance: from 9:30 for the length set by the header key initial_balance: (default 60m). |
prev.high, prev.low, prev.close | The 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):
"0930-1100": start included, end excluded, New York time;"0930-1000,1500-1600": several ranges;"0930-1100:12345": only on the listed days (1 = Monday … 7 = Sunday);"1800-0200": a range may cross midnight; it belongs to the day it starts;"0000-0000": the whole day.
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.
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)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#
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.
tfis a text ("5m","15m","1h","4h","1d") or a duration (15m)."1d"groups bars by CME session. It must be at least the chart's unit and a whole multiple of it (E936 otherwise, e.g. "90s bars cannot be built from 60s bars").symbol:is the symbol of another instrument, written as a literal text: Strate fetches the instruments named this way (up to 8). A symbol held in a variable or a setting finds no bars.exprhas its own memory:request("5m", ema(close, 20))is a real 20-bar EMA of 5-minute bars.exprcannot draw (plot,label,alert… give E936) and cannot read session levels (session.high,prev.close… give E936; read them directly outsiderequest).- Other instruments, live: the one-minute bars recorded by Strate for that symbol. If none exist, E936 "no bars for NQ here". In Replay: the one-minute bars of that symbol for the replayed period, up to the cursor;
naotherwise. - In Replay, the value is also
nawhen the other instrument's last closed minute is more than 30 minutes older than the chart's latest activity in the bar.
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#
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.
| Field | Meaning |
|---|---|
t.time | Time of the trade. |
t.price, t.size | Price and size. |
t.side | "buy" (buyer was the aggressor), "sell", or na if unknown. |
t.delta | Signed size: +size for a buy, −size for a sell. |
t.is_buy, t.is_sell | Bools. |
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)):
| Field | Meaning |
|---|---|
t.sweep | Total size of that aggressive order across all the prices it traded. |
t.levels | Number of distinct prices the aggressive order traded. |
t.sweep_start, t.sweep_end | True on the first / last execution of the aggressive order. Test t.sweep_end to act once per order. |
t.aggressor_id | Id of the aggressive order (na when the feed gives none). |
t.passive_id | First resting order hit at this price. |
t.passive_count | Number 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.
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:
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 = 0Where the data comes from: live, Replay, long backtest#
| Data | Replay of a recorded session (MBO replay files) | Live | Long backtest (local MBO replay files) |
|---|---|---|---|
| Bars (OHLCV, delta) | yes | yes | built from the file's trades (time bars only) |
| Footprint | yes | yes | na |
Trades (on trade) | yes | yes | yes, real executions |
Sweep fields (t.sweep…) | yes, inside the order-by-order window | yes, inside Strate's MBO recording | yes |
Book snapshots (on book, book.*) | yes, every 250 ms | yes, every 250 ms | na |
Order by order (on order, on match, mbo.*, of.ofi) | yes, exactly as in the files | yes, from Strate's own MBO recording | yes |
Session levels (session.*, prev.*) | yes | yes | yes (previous days of the same contract) |
request(…, symbol:) | if that symbol's one-minute bars exist for the replayed period | yes | na |
- Live order-by-order data. When a script reads MBO, Strate starts recording the order-by-order feed for that instrument (up to 8 instruments). A recording starts with a full snapshot of the book, so the book is complete from its first event. Nothing exists before the recording started.
- Replay. The book is rebuilt from the start of the first replay file, then every event is replayed in exchange order. A script never sees anything after the Replay cursor.
- Without order-by-order data,
mbo.availableis false, everymbo.*value isna,on orderandon matchnever run, the sweep fields of trades arena, andof.ofiisna. No error is raised. - Without book data,
book.availableis false and the otherbook.*values arena;on booknever runs. - Live bars. A bar closes once data at or after its end has arrived, or 30 seconds after its end.
A quick way to see what a chart provides:
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:
| Data | Loaded when the text contains |
|---|---|
| Trades | on 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 snapshots | on book, on: book, or the word book |
| Footprint | the word footprint |
| Order by order | on 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:
- Call these functions under their own names. Calling them through another name (
x = mbothenx.level(…)) givesnawithout an error, because the data was never requested. - A
researchscript whose signals come only from bars should also contain anon trade(t) { }handler, so that trades are loaded and its studies can be measured. See Research.