A breakout rule should have a precise information boundary. Build the channel from completed earlier bars, then compare the current confirmed close with that channel.
Published 1 November 2026. Original synthetic example and executable signal check; this is not a historical backtest or a trading recommendation.
Define the comparison first
For a lookback of three bars, define the upper boundary at row t as the maximum high over rows t−3, t−2 and t−1. A long condition is true when the confirmed close at t is strictly above that boundary. Equality is not a breakout in this specification. The first three rows have insufficient history and return no signal.
This is a condition, not an instruction to submit a new order on every true row. A complete strategy still needs position state, entry eligibility and exit rules.
A small example you can inspect by hand
Take highs [10, 11, 12, 14, 13] and closes [9, 10, 11, 13, 12]. At row 3 (zero-based), the previous three highs have maximum 12. The close is 13, so the condition is true. At row 4, the boundary becomes 14 and the close is 12, so the condition is false.
If you include the current high in the channel, a valid OHLC close cannot be strictly above that channel: the close cannot exceed its own high. This is a rule-definition error, distinct from using future observations. Both deserve explicit tests.
Original Python reference implementation
The following uses only the standard language. Inputs must be finite, chronologically ordered, aligned and from one instrument; the compact example does not validate those data requirements.
def breakout(high, close, n=3):
if len(high) != len(close) or n < 1:
raise ValueError("Aligned data and positive lookback required")
return [None if t < n else close[t] > max(high[t-n:t])
for t in range(len(close))]
high = [10, 11, 12, 14, 13]
close = [9, 10, 11, 13, 12]
result = breakout(high, close)
assert result == [None, None, None, True, False]
for end in range(1, len(close) + 1):
assert breakout(high[:end], close[:end]) == result[:end]
print(result)
Why the prefix check matters
The loop recomputes signals using only the data available through each endpoint. Earlier outputs must match the corresponding prefix of the full run. If adding later observations changes an already confirmed signal, investigate centered windows, backward filling, future shifts or normalization fitted on the entire dataset.
Passing this check on five rows is a useful regression test, not proof that a real research pipeline is free of leakage. Revised data, a survivorship-biased universe or features published after their timestamp can pass a prefix check and still introduce unavailable information.
Translating the rule into pandas
boundary = df["high"].rolling(3, min_periods=3).max().shift(1)
condition = df["close"] > boundary
ready = boundary.notna()Use the readiness mask to distinguish insufficient history from a valid false condition. Here shift(1) moves the computed boundary by one row without a frequency argument. Supplying freq changes index labels instead; it is not the same operation. The pandas documentation linked below was checked on 1 November 2026. This pandas snippet is explanatory and was not executed for this note.
A signal is not a fill
The confirmed close is only known after the bar has completed. Do not automatically assign that same price as an executable fill. Specify order creation time, next eligible execution event, spread, slippage, commission and gaps separately. A next-open model must use the next observed open, not a price inferred from the signal close.
Next exercise: change the current close to exactly the boundary and confirm that the strict comparison remains false. Then add a future outlier and confirm that earlier outputs remain unchanged.
Primary references
References reviewed 28 October 2026. Original exercises and project-specific observations are identified separately.
Keep exploring
Review strategy hypotheses ↗Educational engineering and research guidance. Examples do not establish a profitable or live-ready trading strategy.