What Is a Breakout Strategy?
A breakout strategy is a trend-following trading approach that enters a position when the price breaks above the recent high of a defined lookback period.
Simple yet effective, this strategy is ideal as a starting point for algorithmic trading. In this article, we'll walk through the exact breakout logic running in our live US stock auto-trading system, down to the code level.
Why Breakout?
Among the many trading strategies available, we chose breakout for the following reasons:
- Simple logic — Signal generation requires only high/low comparisons
- Few parameters — Just three: lookback period, stop loss, and take profit
- Easy to backtest — Clear entry/exit conditions make validation straightforward
- Automation-friendly — Mechanical decisions free from emotional bias
Algorithm Overview
Our breakout strategy operates in three states:
No Position (Entry Decision)
When the current price exceeds the highest high of the last N bars, a BUY signal is generated.
Current Price > Highest High of last N bars → BUY
Holding Position (Exit Decision)
While holding, three conditions are checked in priority order:
- Stop Loss (highest priority): Current Price ≤ Entry Price × (1 - SL%)
- Take Profit: Current Price ≥ Entry Price × (1 + TP%)
- Downward Breakout: Current Price < Lowest Low of last N bars
Insufficient Data
When there aren't enough bars for the lookback period, the system returns HOLD (no action).
Parameter Design
| Parameter | Default | Description |
|---|---|---|
| Lookback Period | 12 bars | 5-min bars × 12 = last 1 hour |
| Stop Loss | -1% | Threshold to limit losses |
| Take Profit | +2% | Threshold to lock in gains |
Why 12 Bars?
On a 5-minute chart, 12 bars equal the last hour of trading. This was chosen because:
- It's well-suited for day trading timeframes
- Sufficient to filter out noise
- Generates signals at a reasonable frequency during US market hours (6.5 hours)
Risk-Reward Ratio of 1:2
With a -1% stop loss and +2% take profit, we maintain a 1:2 risk-reward ratio. This means the strategy is profitable even with a win rate as low as 34%.
The Breakout Logic in Code
Here's the core logic in TypeScript:
function evaluateBreakout(
bars: Bar[],
currentPrice: number,
position: Position | null,
config: StrategyConfig
): Signal {
const { lookbackPeriod, stopLossPercent, takeProfitPercent } = config;
// Not enough data → HOLD
if (bars.length < lookbackPeriod) {
return "HOLD";
}
const recentBars = bars.slice(-lookbackPeriod);
const highestHigh = Math.max(...recentBars.map(b => b.high));
const lowestLow = Math.min(...recentBars.map(b => b.low));
// Holding position → check exit conditions
if (position) {
const entryPrice = position.entryPrice;
const stopLossPrice = entryPrice * (1 - stopLossPercent / 100);
const takeProfitPrice = entryPrice * (1 + takeProfitPercent / 100);
if (currentPrice <= stopLossPrice) return "SELL"; // Stop loss
if (currentPrice >= takeProfitPrice) return "SELL"; // Take profit
if (currentPrice < lowestLow) return "SELL"; // Downward breakout
return "HOLD";
}
// No position → check entry condition
if (currentPrice > highestHigh) {
return "BUY";
}
return "HOLD";
}
Why Stop Loss Gets Top Priority
The fact that stop loss is checked first in the exit logic is crucial.
During a market crash, take profit and downward breakout conditions may not trigger, but the stop loss must fire reliably. Minimizing losses is the single most important factor for long-term capital preservation.
Summary
The breakout strategy excels as a starting point for auto-trading due to its simplicity:
- Enter when price breaks above recent highs
- Manage stop loss (-1%) as the top priority
- Secure a 1:2 risk-reward ratio with take profit (+2%)
- Optimize for day trading with a 12-bar (1-hour) lookback
In the next article, we'll cover backtest results and our approach to parameter optimization.
FAQ
What market conditions favor the breakout strategy?
It performs best in trending markets with high volatility — particularly right after the US market open and around economic data releases.
Why not use moving averages or MACD?
We prioritize simplicity. Adding more indicators means more parameters, which increases the risk of overfitting. Our approach is to start with minimal logic, validate it, and improve incrementally as needed.
Can this work on timeframes other than 5-minute?
Yes. By adjusting the lookback period, it can be applied from 1-minute to daily charts. However, shorter timeframes are more susceptible to noise and have higher relative transaction costs.
