Momentum trading strategy explained (rules, code and risk)
Momentum is the oldest documented edge in markets: things that have been going up tend to keep going up, at least for a while. A momentum strategy buys strength and rides the trend, cutting losers fast and letting winners run. It has a counterintuitive signature — a low win rate but a high payoff, because a few big trends pay for many small losses. This guide explains the rules, shows the code, and is honest about where momentum bleeds.
The core idea
Momentum says: don't try to catch the bottom, buy what's already strong and ride it. Academically it's one of the most robust anomalies across asset classes and decades. The trade-off is psychological — you buy high and sell higher, which feels wrong but works in trending markets.
The rules
Two common ways to define momentum:
- Breakout — buy when price closes above the highest high of the last N bars; exit on a breakdown below a trailing stop.
- Moving-average trend — long while a fast MA is above a slow MA; flat otherwise (the SMA crossover on our backtester).
The code
python · momentum.pydef signal(highs, closes, n=20):
roll_high = max(highs[-n-1:-1]) # prior N-bar high
return 'buy' if closes[-1] > roll_high else 'flat'
# exit on a trailing stop, e.g. close below 10-bar low
def exit_signal(lows, closes, n=10):
return closes[-1] < min(lows[-n-1:-1])
The signature: low win rate, big winners
Momentum strategies often win only 35–45% of trades — yet they're profitable because the average winner dwarfs the average loser. Judge momentum by expectancy and profit factor, not win rate. Use the profit calculator to see how a 40% win rate with a 3:1 payoff still prints money.
Where momentum bleeds
- Choppy ranges — false breakouts whipsaw you in and out for repeated small losses.
- Sharp reversals — momentum is late by design; it gives back some of every top.
- Crowded trades — when everyone chases the same momentum, reversals get violent.
It's the mirror image of mean reversion: momentum wins in trends and loses in chop, exactly where reversion does the opposite. Run both on the same market in the backtester to feel it.
Sizing and risk
Because individual trades lose often, position sizing is survival. Risk a small, fixed fraction per trade so a string of false breakouts can't bury you before a real trend arrives. Size every entry with the position calculator and keep risk ≤1%.
Frequently asked questions
What is a momentum trading strategy?
Momentum buys assets that are already rising on the premise that strength persists, riding the trend and cutting losers fast. It's one of the most robust documented edges across markets, with a low win rate but large average winners.
Why does momentum have a low win rate?
Because it accepts many small losses from false breakouts in exchange for a few large gains when a real trend develops. The strategy is profitable through payoff ratio and expectancy, not by being right often — judge it by profit factor, not win rate.
When does momentum trading fail?
In choppy, range-bound markets, where false breakouts whipsaw you, and on sharp reversals, since momentum entries are late by design. It's the opposite of mean reversion, which thrives in exactly those ranging conditions.
How do I backtest a momentum strategy?
Define exact breakout and exit rules, simulate with fees and no lookahead, and judge it on expectancy, profit factor and drawdown rather than win rate. Our backtester includes a momentum strategy you can test across trending and ranging markets.