Context
Chart metadata and per-bar execution flags available through the global context object.
The global context object exposes market metadata and execution state.
If you need the normalized string form or timeframe classification helpers, use the timeframe.*. context.timeframe remains the raw chart timeframe in seconds.
Market Fields
| Field | Type | Description |
|---|---|---|
context.timeframe | number | Primary/chart timeframe in seconds |
context.exchange | string | Active exchange |
context.symbol | string | Active symbol |
context.tickSize | number | Minimum price increment |
context.stepSize | number | Minimum quantity increment |
Per-Bar Flags
| Field | Type | Description |
|---|---|---|
context.isFirst | bool | true when current absolute bar index is 0 |
context.isHistory | bool | true during history-run execution path |
context.isLast | bool | true on the last currently available primary-series bar |
context.isNew | bool | true when current unix changed vs previous evaluation |
context.isRealtime | bool | true when not in history execution path |
Example Value
{
timeframe: 60,
exchange: "binancef",
symbol: "btc/usdt",
tickSize: 0.1,
stepSize: 0.001,
isFirst: false,
isHistory: false,
isLast: true,
isNew: true,
isRealtime: true
}Example
//@version=2
indicator("Context Example", true)
const candles = subscribe(data.OHLCV)
function onBar(index) {
if (context.isHistory) return
const rounded = math.roundToTick(candles.close(), context.tickSize)
if (context.isNew) {
plot("Realtime Close", rounded, { color: color.blue })
}
}