[Canonical HTML article](https://algoway.trade/blog/pandas-candle-resampling-boundaries.html)

Published: November 24, 2026

# pandas Candle Resampling: Boundaries vs Time Labels

![pandas Candle Resampling: Boundaries vs Time Labels](https://algoway.trade/static/img/blog-img/pandas-candle-resampling-boundaries.jpg)

A tick stamped 09:35:00 can close one five-minute candle or open the next. Both conventions are possible. The mistake is to change the timestamp printed beside a candle and assume that its contents changed too.

In pandas, **`closed` controls boundary membership; `label` controls the timestamp attached to the result.** Specify both when turning market ticks into candles for an automated strategy. Otherwise a boundary trade can change a close, a high, or a threshold event before any execution request exists.

For an AlgoWay workflow, make this decision in the Python strategy that prepares the signal. The [Python webhook integration guide](https://algoway.trade/blog/python-trading-bot.html) covers sending that decision onward. A correctly delivered order cannot repair a candle assembled from the wrong ticks.

## Which candle owns 09:35?

For five-minute bins aligned to 09:30 and 09:35:

| Membership | Interval | Tick at exactly 09:35 |
| --- | --- | --- |
| `closed="left"` | 09:30 inclusive, 09:35 exclusive | Belongs to the next interval |
| `closed="right"` | 09:30 exclusive, 09:35 inclusive | Belongs to this interval |

Either interval can carry a left-edge or right-edge label. For example, a left-closed interval labeled 09:35 still excludes the tick at 09:35. Its label names the endpoint, not the final observation it contains. The [pandas resample reference](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.resample.html) documents these as separate parameters.

## One boundary trade changes the close

Consider these invented trade prices, all on the same date in UTC:

| Timestamp | Price |
| --- | --- |
| 09:30:00 | 100 |
| 09:34:59 | 101 |
| 09:35:00 | 105 |
| 09:39:59 | 102 |

With left-closed bins and right-edge labels, the candle labeled 09:35 contains 100 and 101. Its open is 100, high 101, low 100 and close 101. The next candle contains 105 and 102.

With right-closed bins and right-edge labels, the candle labeled 09:35 contains 101 and 105. Its open is 101, high 105, low 101 and close 105. The observation at 09:30 sits in the preceding interval, labeled 09:30.

Now imagine a rule that requires a completed candle close above 103. At the row labeled 09:35, the first construction fails that condition and the second passes it. This is an arithmetic illustration, not a strategy performance result. The input prices did not change. Their grouping did.

This reproducible example builds both versions without connecting to a broker:

```python
import pandas as pd

index = pd.to_datetime([
    "2026-11-23 09:30:00+00:00",
    "2026-11-23 09:34:59+00:00",
    "2026-11-23 09:35:00+00:00",
    "2026-11-23 09:39:59+00:00",
])
prices = pd.Series([100, 101, 105, 102], index=index)

left = prices.resample(
    "5min", closed="left", label="right", origin="start_day"
).ohlc()
right = prices.resample(
    "5min", closed="right", label="right", origin="start_day"
).ohlc()

boundary = pd.Timestamp("2026-11-23 09:35:00+00:00")
assert left.loc[boundary, "close"] == 101
assert right.loc[boundary, "close"] == 105
print(left)
print(right)
```

## A timestamp is not a readiness certificate

The [pandas time-series guide](https://pandas.pydata.org/docs/user_guide/timeseries.html#resampling) describes resampling as time-based grouping and warns that labeling choices can pull later information backward. OHLC aggregation collects the first, highest, lowest and last observations in a group. It does not establish when your trading process actually received them.

In a live system, a row labeled 09:35 can already exist while the interval is still forming. Conversely, an exchange-timestamped tick may arrive after your local clock passes that endpoint. Define when your application finalizes a candle and how it handles late data. Recalculating historical candles silently after an order was sent makes an execution audit unnecessarily entertaining.

Keep the candle boundary, signal decision time and data receipt time distinguishable in your records. A historical close stored under an opening timestamp must not become an input available at that opening instant.

## Match the feed before comparing signals

For fixed minute frequencies, `origin` and `offset` can shift the bin alignment. An explicit origin must have a timezone compatible with the index. They do not supply an exchange holiday calendar or decide which overnight session a trade belongs to. The resample reference explains the alignment controls; your feed and strategy specification must supply the session policy.

Before comparing these candles with another platform, record the timestamp timezone, whether prices represent trades or quotes, interval boundaries, labels and session filtering. Sort input observations in their intended chronological order and resolve duplicate timestamps deliberately when their sequence matters to open and close.

Missing observations are a separate problem. Changing a boundary cannot manufacture an absent price; see [missing candles and rolling eligibility](https://algoway.trade/blog/pandas-rolling-min-periods-missing-candles.html) before adding forward-filled values. A useful acceptance check is a tiny fixture containing observations immediately before, exactly on and immediately after the boundary. If those three have unambiguous homes, the larger dataset has a rule worth following.
