Opening Range Breakout AI Trading Bot

Research agent finds stocks breaking the morning high, trading agent buys with a target and a stop, then out before the close

This day trading bot trades the opening range breakout (ORB). It marks each stock’s high and low from the first 15 minutes of the day, then buys the stock that breaks out above that high. Why this setup? A study of a 5-minute opening range breakout on QQQ found 33% a year of return beyond the index after commissions from 2016 to 2023 (Zarattini and Aziz, 2023). Most day trading setups do not hold up that well, so test it yourself.

How it works

  1. Research agent checks 10 big, liquid stocks and ETFs once an hour, starting at 10:00 ET. It finds each stock’s opening range (the high and low from 9:30 to 9:45) and lists the stocks that closed above their range high, best first.

  2. Trading agent buys the best breakout if the bot holds nothing. The stop is the range low, sized so hitting it loses at most 1% of the account.

  3. The trading agent also places a profit target at 1.5 times the risk. It sells if the price falls back into the range, and always before the close.

Change universe to scan different stocks.

Run it on BotSpot

Run this bot on BotSpot without installing anything. BotSpot runs LumiBot in the cloud, backtests it, and connects it to your broker.

Backtest tear sheet

GPT-6 Luna, January 5 to 9, 2026, Alpaca minute prices checked hourly, $100,000 start. The bot traded breakouts in TSLA, AMZN, MSFT, and NVDA, one stock at a time with a target and a stop, and ended at $100,127 (+0.1%) while SPY rose 1%.

Backtest tear sheet for the Opening Range Breakout AI Trading Bot

Open the full tear sheet. A short backtest shows the bot works as written. It is not a promise of future returns.

The code

The whole bot is one short file. The prompts are plain English, and they are the strategy.

"""Opening Range Breakout AI Trading Bot.

Marks each stock's high and low from the first 15 minutes of the day, then buys
the stock that breaks out above that high. A research agent scans a list of big
stocks every hour. A trading agent buys the best breakout with a profit target
and a stop, and is out of the market by the close.
"""

from lumibot.strategies import Strategy


class AIOpeningRangeBreakoutStrategy(Strategy):
    parameters = {"universe": ["SPY", "QQQ", "AAPL", "MSFT", "NVDA", "AMZN", "META", "GOOGL", "TSLA", "AMD"]}

    def initialize(self):
        self.sleeptime = "1H"
        self.agents.create(
            name="researcher",
            allow_trading=False,
            system_prompt=(
                "For each stock in the universe, find today's opening range: the high and low from 9:30 to "
                "9:45 ET. List the stocks that have since closed above their opening range high, best first. "
                "Do not trade."
            ),
        )
        self.agents.create(
            name="trader",
            allow_trading=True,
            system_prompt=(
                "Hold at most one stock. If we hold none, buy the best breakout. The stop is the opening "
                "range low: size the trade so the stop loses at most 1% of the account, and place a profit "
                "target at 1.5 times that risk. Sell if the price falls back into the range, and always "
                "before the close."
            ),
        )

    def on_trading_iteration(self):
        if self.get_datetime().hour < 10:  # the opening range is not finished yet
            return
        facts = {"universe": self.parameters["universe"]}
        research = self.agents["researcher"].run(task_prompt="Find the best breakout.", context=facts)
        self.agents["trader"].run(task_prompt="Trade the breakout.", context={**facts, "research": research.summary})


if __name__ == "__main__":
    from lumibot.credentials import IS_BACKTESTING

    if IS_BACKTESTING:
        from lumibot.backtesting import AlpacaBacktesting

        AIOpeningRangeBreakoutStrategy.backtest(AlpacaBacktesting)
    else:
        AIOpeningRangeBreakoutStrategy().run_live()

Run it yourself

pip install lumibot
python -m lumibot.example_strategies.ai_opening_range_breakout

Put these in your .env file: OPENAI_API_KEY, and your broker keys (for example ALPACA_API_KEY, ALPACA_API_SECRET, and ALPACA_IS_PAPER=true for paper trading). With IS_BACKTESTING=false the bot trades. With IS_BACKTESTING=true it backtests instead; set BACKTESTING_START and BACKTESTING_END to pick the dates, and start with a week or two, because every AI call costs a little. Option and minute-bar backtests use Alpaca’s free history, so paper Alpaca keys are enough.

See AI Trading Bot Examples for more AI trading bots and Backtest, paper, or live: choose the runner for backtest and live runs.