# When trades happen

> The exact timing of every decision and fill: the bar a strategy decides on, the bar it fills on, what an early close changes, and why paper fills differ from the backtest.

Source: https://orbitalaip.com/docs/backtesting/when-trades-happen

> [!IMPORTANT] Disclaimer
> Backtest results are hypothetical and do not predict future performance. Nothing here is investment advice: Orbital computes the rules you supplied and recommends nothing. Orbital is not a registered investment adviser or broker-dealer. Costs are as modelled by the chosen cost profile and may differ from live trading.

## One bar of delay

Every backtested strategy, and every Rules or Program deployment, decides at the close of a bar and trades on the next one. In a backtest, a market order [fills](https://orbitalaip.com/docs/glossary#fill) at the next bar's open plus [slippage](https://orbitalaip.com/docs/glossary#slippage), 5 bps unless the run changes it. The strategy never sees the bar it trades on.

The decision bar is the strategy's [timeframe](https://orbitalaip.com/docs/glossary#timeframe), and the fill bar is not always the same size. An intraday strategy fills at the open of the next one-minute bar, whatever its decision bar, because every intraday backtest runs on minute bars. A decision on a [session](https://orbitalaip.com/docs/glossary#session)'s last bar carries overnight and fills at the next session's first bar.

## Daily strategies

A daily strategy decides on a session's completed bar and fills at the next session's opening bar. Each entry is sized at the decision bar's close by default. **Size at the fill** sizes it at its fill price instead: the largest whole number of shares its sizing rule and the account allow, after costs.

In the Run dialog, **Change…** on the **Costs and fills** row opens **How orders fill**, which offers two other choices. **At the next session’s close** fills entries at the next session's official close and sizes them at that fill; exits still fill at the next open. Under the limit policy, each entry rests at an offset from the decision bar's close, and exits stay market orders. **When a bar reaches your price** sets when it fills. The recommended rule waits for a later bar to trade through the price; the other fills as soon as one touches it. Limit fills never slip.

Stops and targets are tested against each bar's path: the open, the nearer extreme, the farther extreme, then the close. A stop that gaps through fills at the worse of its trigger and the bar's open. A trailing stop updates at each close and can fire from the next bar. A time stop exits at the open after the set number of completed bars.

## Intraday strategies

An intraday strategy decides on whole-minute bars during regular hours, 09:30 to 16:00 ET. A regular session has 391 minutes, the last of them the closing print at 16:00 ET, so a strategy on a 1-minute bar decides about 391 times a session. On a longer bar, the session's last window is cut short at the close.

No bar is published for a minute in which a symbol did not trade, so on a thin name an order waits for the symbol's next real bar. The engine treats a fill more than five minutes after its order as a stale fill, and **Run properties** on the **Report** tab states that rule under **Stale fills**; no trade row is marked. Indicator windows count real bars, not clock minutes.

## Early closes

On the exchange's scheduled early closes, such as the day after Thanksgiving, the session ends at 13:00 ET. A backtest treats it as a short session: 211 minutes, the last at 13:00 ET, and still one daily bar.

A [program](https://orbitalaip.com/docs/glossary#program) reads the session's last minute from `session_last_minute()`: 390 on a regular day and 210 on an early close, counting from the 09:30 ET open.

On paper, an intraday deployment's last step reads the 13:00 ET closing print. An Agent strategy on the five-minute schedule decides from 09:30 to 12:55 ET that day. One on a daily schedule makes no decision, because its 15:45 ET check falls after the close.

## Forward tests

Each [forward test](https://orbitalaip.com/docs/glossary#forward-test) update re-runs the frozen run with only its end date moved, so its fills follow the backtest rules. See [How updates work](https://orbitalaip.com/docs/backtesting/forward-testing#how-updates-work).

## Paper deployments

On [paper](https://orbitalaip.com/docs/glossary#paper-trading), a Rules or Program deployment sends day market orders in whole shares, and the broker's fill from Alpaca's paper simulator can land away from the open the backtest modelled. See [Orders on Alpaca paper](https://orbitalaip.com/docs/trade/deploy-a-strategy#orders-on-alpaca-paper). A backtest that fills at a limit price or at the next session's close cannot be deployed, nor can an intraday backtest sized at the fill; see [Why a deploy is refused](https://orbitalaip.com/docs/trade/deploy-a-strategy#why-a-deploy-is-refused).

In a Rules or Program deployment, a stop, target or trailing stop is checked against each completed minute bar during the session. A crossing exits at market, so the fill can land past the level the backtest used.

> [!NOTE] Agent strategies
> An Agent strategy runs on a schedule, not on bars: once a day at 15:45 ET, or every five minutes from 09:30 to 15:55 ET, on trading days. The **Deployments** drawer's **CHECKS** column, under **READY TO DEPLOY**, says which. Its orders go through its trading permission; see [The trading permission](https://orbitalaip.com/docs/trade/approvals-and-permissions#the-trading-permission).

### Intraday deployments

A Rules or Program [deployment](https://orbitalaip.com/docs/glossary#deployment) on minute bars is stepped a few seconds after each minute ends, on the bar that just closed. An entry decided during the session is sent at once, sized at the moment it decides. An entry decided on the session's last bar is held overnight and sent between 09:00 and 09:28 ET the next trading morning, queued for the open. One not sent by then is dropped rather than filled late. Apart from those queued entries, Orbital refuses a new market entry while the market is closed or inside its last five minutes.

### Daily deployments

A Rules or Program deployment on daily bars decides each trading morning at about 08:30 ET, on the previous session's final prices. Its buys and sells are sent before the 09:30 ET open as market orders queued for the open. Each buy is sized on those final prices, not at its fill.

Its stops follow the minute-bar rule above. Some crossings exit at the next open instead: one in the last minute, at the close, while prices are unavailable, or on a day the name splits. So does a time stop. Both rules are shown as warnings when you deploy it.
