No look-ahead
A rule in Matana Labs sees only what was known at the end of the current second: the second’s price and bars that have already closed. Its market orders fill at that second’s price and its resting orders from the next second. A test that changes the future of the data checks this on every build.
What a rule sees at a given second
| Value | What it is at second t |
|---|---|
| price | The price of second t, known when that second ends |
| An indicator or bar on intraday bars (1m, 5m, 1h…) | The last bar that closed before second t; the bar still forming is never read |
| Daily bars (close[1d], SMA(…)[1d]) | Yesterday’s bar: today’s daily bar is not used until tomorrow |
| Weekly bars | The last week that has ended |
| Day values (day.high, day.low) | Up to and including second t |
| Yesterday (day.prev_close…) | The previous session |
| Bars back (close[5m]~2) | Counted back from the last closed bar; offsets cannot point forward |
A bar is closed from the first second after its last second. A 5-minute bar from 10:00 to 10:05 is first read in the second that ends at 10:05:01. Indicators on intraday bars continue across days, so an indicator at the open uses yesterday’s bars, never later ones.
When orders fill
- Market orders fill at the price of the second in which the rule fired: the same price the rule could see, never an earlier one and never a later one. A rule cannot fill at the close of a bar it only learned about after the bar ended.
- Limit and stop orders a rule places are checked from the next second (unless
fillSameSecondis turned on, off by default). - A stop, target or trailing stop of a new position is checked from the next second.
- For a stricter test, an execution delay of up to 3,600 seconds fills rule orders at the price of a later second; the Execution delay check measures how much the result depends on speed.
Formulas and your own indicators
The formula language refuses a shift into the future: shift(close, -3) is an error, not a value. Window lengths and other parameters must be numbers; a series in that place would be read at the day’s last bar, so it is refused too.
The test that checks it
Two copies of the same data are built, identical except that one day’s prices from 13:00 on are raised by 3% and its volumes doubled. Several strategies run on both: crossovers on 5-minute bars, a Donchian breakout on 15-minute bars, RSI(2), a rule on daily bars with a trailing stop, and limit orders with a lifetime and a stop and target. Every fill before 13:00 of that day, and on every earlier day, must be identical on both copies; after 13:00 they must differ, which shows the test can fail. It runs with the engine’s other checks on every change (tools/check_method.py).
The engine validation adds a second, independent view: a reference backtester written separately, which only ever reads closed bars, gives the same trades as the engine.