Skip to content
All library documents

OHLCV Bars, Their Data Fields, and Execution Timestamps

Article NautilusTrader

Summary

This reference explains how a bar represents open, high, low, close, and volume data for a specified bar type. A venue or provider may supply bars, or a trading system may build them from quote ticks, trade ticks, or smaller bars. Bar type carries information about the instrument, aggregation, price type, and source; composite types can also identify a source bar type.

The document specifies required price, quantity, and timestamp fields, along with consistency rules: the high must be at least as large as the open and close, while the low must be no greater than either. For execution simulation, the initialization timestamp should correspond to the bar’s close so a complete bar is not exposed before it has formed. The example demonstrates object construction in Rust and Python, but the page is a data-model reference rather than a trading strategy. It does not discuss signal generation, trading performance, or how to choose an aggregation interval.

Key ideas

  • A bar packages OHLC prices and volume for an instrument and a defined bar type.
  • Bars can come from an external provider or be aggregated from tick data or smaller bars.
  • The high and low must satisfy consistency constraints relative to the open and close.
  • For execution simulation, the initialization timestamp should mark the bar interval’s close.

Tags

Full text
# Bar


# Bar

`Bar` represents OHLCV price and volume data for a specific `BarType`. A venue or data provider
can supply bars, or NautilusTrader can aggregate them from quote ticks, trade ticks, or smaller bars.

## Fields

| Field      | Rust type   | Python type | Required/default | Notes                                            |
| ---------- | ----------- | ----------- | ---------------- | ------------------------------------------------ |
| `bar_type` | `BarType`   | `BarType`   | Required         | Instrument, aggregation, price type, and source. |
| `open`     | `Price`     | `Price`     | Required         | First price in the bar interval.                 |
| `high`     | `Price`     | `Price`     | Required         | Highest price in the bar interval.               |
| `low`      | `Price`     | `Price`     | Required         | Lowest price in the bar interval.                |
| `close`    | `Price`     | `Price`     | Required         | Last price in the bar interval.                  |
| `volume`   | `Quantity`  | `Quantity`  | Required         | Traded volume or tick-volume proxy.              |
| `ts_event` | `UnixNanos` | `int`       | Required         | Bar event timestamp in nanoseconds.              |
| `ts_init`  | `UnixNanos` | `int`       | Required         | Initialization timestamp in nanoseconds.         |

## Behavior

- `high` must be greater than or equal to `open`, `low`, and `close`.
- `low` must be less than or equal to `open` and `close`.
- `bar_type` determines whether a bar is internal or external.
- Composite bar types use `@` syntax to identify the source bar type.

:::warning[Bar timestamps for execution simulation]
For execution simulation, `ts_init` must represent the close of the bar interval, which prevents
the complete bar from becoming visible before it formed. See
[bar timestamp convention](../backtesting/bar-execution.md#bar-timestamp-convention).
:::

## Example

```rust tab="Rust"
use nautilus_core::UnixNanos;
use nautilus_model::{
    data::{Bar, BarType},
    types::{Price, Quantity},
};

let bar = Bar::new(
    BarType::from("AUD/USD.SIM-1-MINUTE-LAST-EXTERNAL"),
    Price::from("0.65000"),
    Price::from("0.65010"),
    Price::from("0.64990"),
    Price::from("0.65005"),
    Quantity::from("1000000"),
    UnixNanos::from(1_000_000_000),
    UnixNanos::from(1_000_000_100),
);
```

```python tab="Python"
from nautilus_trader.model import Bar
from nautilus_trader.model import BarType
from nautilus_trader.model import Price
from nautilus_trader.model import Quantity

bar = Bar(
    bar_type=BarType.from_str("AUD/USD.SIM-1-MINUTE-LAST-EXTERNAL"),
    open=Price.from_str("0.65000"),
    high=Price.from_str("0.65010"),
    low=Price.from_str("0.64990"),
    close=Price.from_str("0.65005"),
    volume=Quantity.from_int(1_000_000),
    ts_event=1_000_000_000,
    ts_init=1_000_000_100,
)
```

## Related guides

- [Bars and aggregation](index.md#bars-and-aggregation) covers aggregation methods.
- [Bar types](index.md#bar-types) explains `BarType` string syntax.
- [Python API reference](/docs/python-api-latest/model/data.html) lists Python members.

Shown in full with attribution under the source's licence. Licence: LGPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.