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.

On this page
  1. The core idea
  2. The rules
  3. The code
  4. Low win rate, big winners
  5. Where it bleeds
  6. Sizing & risk
  7. FAQ

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:

20-bar high BUY breakout ride the trend
Entry triggers the moment price clears the rolling high; the bot rides the trend until a breakdown exits.

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

Win rate is the wrong metric here

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

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%.

Not financial advice. This content is educational. Automated and algorithmic trading carries a real risk of financial loss. Never trade money you cannot afford to lose. Review the SEC investor.gov and CFTC resources before trading.

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.

MB

Mustafa Bilgic

Algorithmic trading practitioner · Founder, AITradingBot.us

Mustafa builds and backtests automated trading systems and writes about them without the hype. Every tool on this site is free and runs entirely in your browser.