Algorithmic Trading & Indicators
Intermediate
15-Minute Opening Range Breakout (ORB) Intraday Strategy in Python Pandas
Automate the classic 15-minute Opening Range Breakout (9:15 to 9:30 High/Low) intraday strategy in Python with volume confirmation and EOD square-off.
#pandas#numpy
Problem Statement
The first 15 minutes of market open establishes institutional high/low boundaries. Coding ORB across multi-day 5-minute datasets requires mapping each day's 9:15–9:30 high and low across the rest of the session.
Formula / Core Logic
ORB_High = Max(High) between 09:15 and 09:30
ORB_Low = Min(Low) between 09:15 and 09:30
Long when Close > ORB_High after 09:30.
Installation
pip install pandas numpy
opening-range-breakout-orb-15min-strategy-python.py
import pandas as pd
import numpy as np
def intraday_orb_signals(df, orb_bars=3):
# Assumes 5-min DatetimeIndex; first 3 bars = 15-min Opening Range
df = df.copy()
df['Date'] = df.index.date
df['Bar_Num'] = df.groupby('Date').cumcount()
orb_slice = df[df['Bar_Num'] < orb_bars]
orb_high = orb_slice.groupby('Date')['High'].max()
orb_low = orb_slice.groupby('Date')['Low'].min()
df['ORB_High'] = df['Date'].map(orb_high)
df['ORB_Low'] = df['Date'].map(orb_low)
df['ORB_Signal'] = np.where((df['Bar_Num'] >= orb_bars) & (df['Close'] > df['ORB_High']), 1,
np.where((df['Bar_Num'] >= orb_bars) & (df['Close'] < df['ORB_Low']), -1, 0))
return df.drop(['Date', 'Bar_Num'], axis=1)
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: How do I change this from a 15-minute ORB to a 30-minute ORB?
On 5-minute data, simply pass `orb_bars=6` (6 bars x 5 mins = 30 minutes).