Guides · Updated 2026-11-09 · Backtest and paper results only, not financial advice.
HMM Regime Switching Strategy: A Viral Bull/Bear Bot Backtested Since 2019
An HMM regime switching strategy did what it promised in our backtest, smaller crashes, but it made far less money than simply holding the market. A viral bot we tested, which uses a hidden Markov model to label each day bull, bear or sideways, turned $10,000 into $19,066 (+90.7%) on SPY from 2019-01-02 to 2026-11-09. Buying SPY and doing nothing turned the same $10,000 into $34,046 (+240.5%). The regime bot's worst drop was only -11.0%, against -33.7% for SPY. Below is how it works, where it helped, and what it cost. All results are backtests or paper trades, not financial advice.
The viral bot we tested
The idea came from an X post about someone who built a fully automated trading bot in 34 minutes that detects bull, bear and sideways markets and switches strategies to match. It was seen about 450,000 times. The post didn't publish exact rules, so this is our approximation, which we call the 34-minute regime bot. The rules:
- Bull regime: hold SPY.
- Bear regime: sell and sit in cash.
- Sideways regime: trade short dips with the 2-period RSI, a mean-reversion signal popularized by Larry Connors. Buy when RSI(2) drops below 10, sell when it rises above 70.
We run every bot the same way in our engine: $10,000 to start, signals on the daily close, fills at the next day's open, 0.05% slippage per fill, no commission, and adjusted daily prices from Yahoo Finance. The exact prompt is free on the prompts page.
How the HMM decides the regime
A hidden Markov model assumes the market is always in one of a few states you can't see directly, and it estimates which one from things you can see. Our version, built with the open-source hmmlearn library, looks at two numbers each day: the daily return and the 20-day volatility. It sorts the three states it finds by average return and calls them bear, sideways and bull.
The part most viral HMM posts get wrong is timing. If you fit the model on the whole history and then backtest on that same history, the model already knows where the crashes were. We used a walk-forward setup instead: the model trains only on the previous ~3 years, gets refit about every quarter, and labels each day using data up to that day. That is slower and less flattering, but it's the only version you could have actually traded.
The results vs buy-and-hold
| Ended with | Return | Per year | Worst drop | Sharpe | Trades | |
|---|---|---|---|---|---|---|
| HMM regime bot | $19,066 | +90.7% | +8.6% | -11.0% | 0.88 | 66 |
| Buy and hold SPY | $34,046 | +240.5% | +16.9% | -33.7% | 0.91 | 0 |
Hypothetical backtests from 2019-01-02 to 2026-11-09, $10,000 start, daily bars, next-day fills. Not advice.
That's +8.6% a year for the regime bot against +16.9% for holding, a gap of about 150 percentage points in total. Its worst drop was roughly 33% the size of SPY's, which is the real selling point. But on a risk-adjusted basis it still didn't win: its Sharpe ratio, which scores return per unit of bumpiness, was 0.88 vs 0.91 for SPY. It was invested only about 44% of the time.
Every trade, in plain numbers
In 7 years the bot closed 66 trades and is holding one more. 44 made money and 22 lost, a 67% win rate. That high win rate comes from the sideways dip-buying, which sells into small bounces.
- Average winner: +2.2%. Average loser: -1.5%.
- Quick trades: 49 trades lasted 10 days or less and made $3,938 combined. Long holds: 12 trades lasted a month or more and made $4,484.
- Best trade: +9.5%, from Nov 27, 2023 to Feb 7, 2024.
- Worst trade: -6.9%, from Feb 6, 2025 to Mar 18, 2025.
- Longest hold: 204 days, from Apr 13, 2023 to Nov 3, 2023.
A 67% win rate sounds great, but it says little on its own. Our red flags guide explains why a high win rate can hide a weak strategy. Here, the wins are small and the bot misses long stretches of the market going up.
Where it helped: the 2020 crash
The bot's best call and its most expensive one were the same trade. It sold SPY on Feb 5, 2020, before the COVID crash, and didn't buy again until Aug 5, 2020: 182 days in cash. Buy-and-hold SPY's worst drop in our window came in that crash (Feb 2020 to Mar 2020), and the regime bot skipped all of it. But the market bottomed in March and rallied hard while the bot waited. The model, trained on the calmer years before, kept reading the new, volatile market as bear or as sideways without a deep enough dip, so the bot missed most of the rebound.
Where it hurt: choppy markets and fast reversals
In 2022, when SPY kept falling and bouncing, the bot opened 14 trades and together they made $1,065. Holding SPY through the same year lost about 20% on our weekly curve, so this is where the regime filter earned its keep. It was still busy work: lots of small wins and losses as the regime labels flipped in a choppy market. The worst single trade came in Feb 2025: bought on Feb 6, 2025 and sold on Mar 18, 2025 for -6.9%. The bot labels regimes from past returns and volatility, so by the time a sell-off looks like a bear market, part of the drop has already happened. It then sold again at the open on Apr 3, 2025, as the April 2025 tariff sell-off began, and stayed out until May 16, 2025.
The bot's own worst stretch ran from Dec 2024 to May 2025, a -11.0% drop, and it was back at its old high by Jan 2026. For comparison, a viral 20/50 moving average crossover bot we tested made +84.9% with a worst drop of -28.2%. The HMM bot is the smoother ride of the two. It's not the bigger earner. Our crossover backtest guide has that bot's full story.
Where the bot stands now
As of 2026-11-09 the backtest is holding SPY, bought on Nov 6, 2026 and up +2.6% since then. We're also paper trading the bot forward since 2026-10-16, with simulated fills and no real money. So far it's at +3.3% with 1 closed trade and a position opened on Nov 6, 2026. A few weeks of paper trading proves almost nothing, but it checks that the live rules match the backtest. Our paper trading guide shows the setup.
Can ChatGPT or Claude build this bot?
Partly, and the gap is instructive. On Oct 16, 2026 we gave ChatGPT Free (GPT-5.x "Instant" model; exact name not shown) our HMM prompt. It built a real walk-forward model and we found no look-ahead bug. But its backtest came out at +105.3% vs +83.8% for ours on the same rules (67 trades vs 64). Those figures are from the test date, so they differ slightly from today's. HMM results swing on details the prompt left open: how states get labeled, the random seed, and how today's state is picked. It also filled trades on unadjusted prices and its paper mode wasn't the strategy, so we graded it Partial. We've since tightened the prompt. The full test is in can ChatGPT or Claude build a trading bot?
If you want to try a regime-switching bot
- Insist on walk-forward fitting. If an HMM backtest fits one model on all the data, ignore the result. Our backtesting checklist covers this and other look-ahead traps.
- Pin the random seed and the labeling rule. Two honest versions of the same idea were about 21 points apart in our prompt test.
- Decide what you're buying. In this test the bot's worst drop was about 33% of SPY's, and its total return was about 38% of SPY's. That trade-off may suit you, or not.
- Paper trade first. The broker AI tracker shows which brokers let a bot place orders and which have paper modes.
- Check costs if you buy a tool. Some platforms sell regime detection as a feature. The tools directory lists sourced prices. We haven't tested any of them yet.
The bottom line
An HMM regime switching strategy, built honestly with walk-forward fitting, kept a viral SPY bot's worst drop to -11.0% since 2019, but it made +90.7% while buy-and-hold made +240.5%. It's a smoother ride with a much smaller payoff, and the model is slow to admit when a crash has ended. See how it ranks on the leaderboard, and read do AI trading bots work? for the full picture. These are hypothetical backtests and paper trades of a viral bot we tested, and none of it is financial advice.
FAQ
Does an HMM regime switching strategy work?
It cut risk a lot but gave up most of the return in our test. A viral HMM bull/bear/sideways bot we rebuilt turned $10,000 into $19,066 (+90.7%) on SPY from 2019-01-02 to 2026-11-09, while buying and holding SPY made +240.5%. Its worst drop was -11.0% vs -33.7%. These are hypothetical backtests, not financial advice.
What is a hidden Markov model in trading?
A hidden Markov model assumes the market is always in one of a few unseen states, such as calm-and-rising or volatile-and-falling, and estimates which one it's in from things you can measure, like daily returns and volatility. A regime-switching bot then uses a different rule in each state.
How do you avoid look-ahead bias with an HMM?
Fit the model only on data before the day you trade, refit it on a schedule (walk-forward), and label today's state using data up to today only. Fitting one HMM on the whole history and then backtesting on it lets the model see the future, which makes results look far better than they would have been.
Why did the regime bot trail buy-and-hold?
It was in the market only about 44% of the time. It sat in cash for 182 days in a row in 2020, missing most of the rebound after the COVID crash, and many of its 66 trades were short dip-buys that made small amounts. In a market that mostly went up, being out that often was expensive.
Can ChatGPT build an HMM trading bot?
Partly. When we gave ChatGPT our HMM prompt, it built a proper walk-forward model with no look-ahead we could find, but its backtest came out at +105.3% vs +83.8% for ours, because HMM results are sensitive to details like how states are labeled and the random seed. We graded it Partial.
Get the weekly receipts. Subscribe free and get the Bot Builder Starter Kit (14-page PDF): 5 tested prompts, a hype-detector checklist, and safe paper-trading rules.
Form not showing? Subscribe on beehiiv
Related guides
- Do AI Trading Bots Actually Work? What 5 Viral Bots Did in Backtests
- Can ChatGPT or Claude Build a Trading Bot? We Graded 5 Prompts
- Which Brokers Let AI Trade for You? Robinhood, Alpaca, IBKR and 12 More
- Is That AI Trading Bot Legit? 10 Red Flags to Check First
- How to Paper Trade an AI Trading Bot: Brokers, Setup and Pitfalls
- Can ChatGPT Trade Stocks for You? What It Can and Can't Do
- How to Backtest a Trading Bot (Free, in Python): A Checklist From 5 Viral Bots
- Do Crypto AI Trading Bots Work? 2 Viral Bots vs Holding Bitcoin
- Moving Average Crossover Backtest: A Viral 20/50 SPY Bot Since 2019
- How Much Do AI Trading Bots Cost? Prices of 54 Tools Compared