MAE: optimize stop losses through backtesting

13 min read
BacktestingStop-lossMaeAdvanced-analysisMetrics

Maximum Adverse Excursion (MAE) is the backtesting metric that measures the worst adverse price movement against a position from entry to close, enabling scientific calibration of stop loss placement. Unlike empirical methods (fixed X pips, uniform X ATR across all trades), MAE relies on the actual behavior of your strategy tested on historical data. The result: stop losses adapted to the effective volatility of each setup, neither too tight (premature exit) nor too wide (excessive risk).

According to ESMA (European Securities and Markets Authority), 74 to 89% of retail client accounts lose money when trading CFDs, with average losses per client ranging from EUR 1,600 to EUR 29,000 depending on the country. A significant portion of these losses stems from poorly calibrated stop losses: too tight, they exit trades that would have been profitable; too wide, they let losses run unnecessarily. MAE provides a methodological answer to this problem.

What is Maximum Adverse Excursion (MAE)?

Definition: the worst adverse move before close

For each trade in your backtest, MAE answers a simple question: how far did the price move against me before the position was closed?

Concrete example on a long trade (buy):

  • Entry: 1.2000 (buy EUR/USD)
  • Lowest price reached during the trade: 1.1950
  • Exit (take profit): 1.2080
  • MAE of this trade: 50 pips (or 0.42% of the entry price)

Even though this trade ended in profit, the price pulled back 50 pips at some point. If your stop loss had been placed at 45 pips, you would have been exited before the price reversed toward the take profit.

MAE can be expressed in points, pips, currency units, or as a percentage of the entry price. The percentage expression is preferable for comparing trades across different assets or periods of varying volatility.

Formula for a long trade:

MAE = (Entry Price - Minimum price reached during the trade) / Entry Price x 100

Formula for a short trade:

MAE = (Maximum price reached during the trade - Entry Price) / Entry Price x 100

OHLC data required

Calculating MAE requires access to OHLC (Open, High, Low, Close) data for each candle during the trade duration. The minimum price (or maximum for a short) corresponds to the lowest (or highest) value across all candles between entry and exit. A backtest without precise OHLC data will underestimate actual MAE and produce poorly calibrated stop losses.

Difference from maximum drawdown

MAE differs from maximum drawdown, which is a global strategy metric:

MetricScopeUnitPrimary use
MAEPer individual tradePips, %, currencyCalibrate stop loss for an entry
Maximum drawdownSequence of trades (portfolio)% of capitalEvaluate overall strategy resilience
Median MAEAll backtest trades%, pipsSet default stop loss parameter
90th percentile MAE90% of backtest trades%, pipsConservative stop loss threshold

Drawdown measures the cumulative decline in capital across a series of consecutive losing trades. MAE measures the intra-trade pullback of an individual position. Both metrics are complementary and should be analyzed together in any rigorous backtest. For a deeper look at global backtest metrics, see our guide on expectancy and profit factor.

How to calculate MAE on your trades

Formula and required data (historical OHLC)

Calculating MAE requires access to intra-trade price data: the series of candles between the entry and exit moment of each position.

Required data per trade:

  • Exact entry time and price
  • Exact exit time and price
  • For each candle between entry and exit: Open, High, Low, Close

For a daily backtest on H4 candles, 10 trades represent on average 10 x 6 candles = 60 candles to process for the 10 individual MAE values. On intraday strategies with hundreds of trades, this means thousands of candles to handle. Backtrex fully automates this calculation during backtest execution. Explore the analysis features on the Backtrex features page.

MAE per trade: reading the scatter plot

The key visualization for MAE analysis is the scatter plot, which shows for each trade:

  • X axis: MAE of the trade (maximum pullback, expressed as %)
  • Y axis: final result of the trade (profit or loss, expressed as %)

This chart immediately reveals an essential pattern: do winning trades cluster with low MAE (they do not pull back much before progressing), or do some winning trades experience significant drawbacks before reversing?

Reading the scatter:

Case 1: winning trades cluster with low MAE (0 to 0.5%) and losing trades have high MAE. Signal that your strategy generates clean trades with few false starts. A tightened stop loss at 0.6-0.8% would be coherent.

Case 2: winning trades extend up to 1 to 2% MAE before reversing. Placing a stop loss at 0.5% would prematurely exit a significant proportion of these winning trades.

Statistical distribution of MAE

Beyond the scatter plot, analyzing the statistical distribution of MAE on winning trades provides objective and defensible thresholds.

MAE percentile (winning trades)Stop loss interpretation
50th percentile (median)Aggressive stop: exposes 50% of winning trades to premature exit
75th percentileStandard stop: 25% of winning trades reach this maximum pullback
90th percentileConservative stop: only 10% of winning trades reach this pullback
95th percentileVery conservative stop, suited for high-variability strategies
> 95th percentileStop too wide: disproportionate risk relative to the statistics

Mandatory anti-repainting rule

In every backtest, each entry signal must use the closing price of the previous candle (close[1]), never the current bar (close[0]). A backtest with repainting overstates performance and distorts actual MAE calculations. Backtrex applies this rule systematically to ensure results that accurately reflect real market conditions.

Using MAE to optimize stop losses

Identifying the optimal stop loss threshold

The MAE approach to defining the optimal stop loss follows a clear logical sequence:

1

Backtest without a constraining stop loss

Run an initial backtest with a very wide stop loss to collect the actual MAE of each trade without premature exit bias.
2

Analyze the MAE distribution of winning trades

Identify the 90th percentile of MAE across winning trades. This threshold means 90% of profitable trades did not pull back any further.
3

Add a safety buffer

Add 20 to 30% to the calculated 90th percentile to absorb exceptional fluctuations and avoid stops triggered by temporary volatility spikes.
4

Validate with a new backtest

Rerun the backtest with this calibrated stop loss. Measure the impact on the number of prematurely exited trades and the overall profit factor.
5

Compare profit factor before and after

A properly calibrated stop loss via MAE improves profit factor by reducing exits on trades that would have been winners with more room to breathe.

Avoiding stop losses that are too tight

A stop loss that is too tight is one of the most expensive errors in trading. It typically stems from intuition (the trade should win quickly) or an arbitrary constraint (never more than X pips of risk). MAE reveals exactly what this intuition actually costs.

If your winning trades have a median MAE of 1.2% and your stop loss is placed at 0.8%, you are potentially exiting around 50% of your winning trades before they reach their target. On 100 trades with a theoretical win rate of 55%, a stop that is too tight can drop the actual win rate to 35% in real conditions.

To deepen your understanding of classic backtesting errors to avoid, see our guide on common backtesting mistakes.

The MAE/MFE ratio: measuring asymmetry

MFE (Maximum Favorable Excursion) is the counterpart to MAE: it measures the maximum gain reached by the position before its close. The MAE/MFE ratio reveals the quality of your entries and exits:

MAE/MFE ratio below 1 (ideal): the trade advances more than it retreats. Your entry quality is good and timing is on point.

MAE/MFE ratio close to 1: the trade pulls back as much as it progresses. Market noise is high or the entry is less precise.

MAE/MFE ratio above 1: the trade pulls back more than it advances. Sign that the take profit is hit too early or the entry is poorly timed.

A low MAE/MFE ratio across all winning trades indicates your strategy generally enters in good conditions. Conversely, a high ratio suggests widening the stop and revisiting entry logic.

MAE/MFE and dynamic stop management

Analyzing MFE also reveals opportunities for moving the stop to breakeven or applying a trailing stop. If your winning trades reach on average 2% MFE before pulling back to 0.8% MAE, you can move your stop to breakeven once the position reaches +1.5%, without statistically missing out on profitable trades.

MAE analysis with Backtrex

Backtrex automates the calculation and visualization of MAE on each backtest, without external data manipulation or spreadsheets.

Exporting trade data

At the end of each backtest, Backtrex generates a detailed results table including for each trade: MAE (in % and currency), MFE (in % and currency), final result, trade duration, and intra-trade drawdown. This data can be exported to CSV for in-depth analysis or comparison across configurations.

Visualizing the MAE/MFE scatter plot

The Backtrex interface displays the native scatter plot of MAE versus final result, color-coded by status (winning trade in green, losing in red). At a glance, you identify:

  • The cluster of winning trades and their maximum MAE
  • Outliers (winning trades with high MAE, statistical exceptions)
  • The statistical separation between winning and losing trades based on MAE

Adjusting rules and relaunching the backtest

The power of Backtrex lies in its iteration loop: from the MAE analysis, you modify the stop loss of your strategy in seconds through the visual rule blocks, then relaunch the backtest to immediately measure the impact on profit factor and drawdown.

For traders targeting funded accounts, prop firm challenge drawdown rules impose strict constraints: the FTMO challenge requires a maximum daily drawdown of 5% and a maximum total drawdown of 10% of initial capital. Optimizing stop losses via MAE is essential to stay within these limits while maximizing opportunities. Our guide on backtesting with prop firm rules details this approach.

To go further in your strategy analysis, explore our guides on risk-reward ratio optimization in backtesting and building robust strategies that resist overfitting.

Important Risk Warning

Trading financial instruments involves significant risk of capital loss. Past performance does not guarantee future results. Backtest results presented on this platform are based on historical data and do not constitute investment advice. You should not invest money you cannot afford to lose. Always consult a qualified financial advisor before making any investment decisions.

Conclusion

Maximum Adverse Excursion transforms an intuitive decision (where should I place my stop loss?) into a data-driven decision grounded in your strategy's historical behavior. By analyzing the worst price pullback of your winning trades, you identify an objective threshold below which your strategy rarely falls before advancing toward profit. Add a 20 to 30% buffer, and your stop loss becomes statistically defensible rather than purely instinctive. Try MAE analysis on your next strategy on Backtrex and measure the impact on your profit factor.

MAE measures the worst adverse price movement experienced by a position between entry and close, whether the trade ends in profit or loss. It represents the maximum pullback experienced on each individual trade. When analyzed as a distribution across all winning trades in a backtest, it identifies the threshold below which profitable positions typically do not fall, enabling scientific calibration of stop loss placement.

By plotting the MAE scatter plot of all your winning trades from a backtest, you identify the historical maximum pullback before reversal. Place your stop loss at the 90th percentile of this distribution, then add a 20 to 30% buffer to absorb exceptional fluctuations. This stop will be statistically consistent with the actual behavior of your strategy on historical data.

MAE (Maximum Adverse Excursion) measures the worst pullback against your trade; MFE (Maximum Favorable Excursion) measures the maximum gain reached before close. Together, both metrics define the quality of your entries and exits. A low MAE/MFE ratio (the trade advances much more than it retreats) signals good entry quality and allows for a tighter stop loss.

MAE analysis is particularly effective for trend-following strategies and breakout entries, where winning trades have a clear directional momentum after entry. It is less discriminating for mean-reversion strategies, where healthy trades often pull back significantly before progressing. In that case, analyzing MAE by specific setup type yields more relevant results.

A minimum of 50 to 100 winning trades is necessary for the MAE distribution to be representative. Below 30 trades, the 90th percentile is too sensitive to outliers. The more trades, the more stable the calculated MAE threshold will be and the more transferable to future conditions. Backtrex lets you backtest across multiple years of data to reach these statistical significance thresholds.

MAE is not predictive in the strict sense: it describes the past behavior of your strategy. It provides a statistical basis for sizing the stop loss, but does not guarantee that future trades will follow the same pullback distribution. It must be supplemented with robustness testing (forward testing, Monte Carlo) to validate its relevance outside the training data. See our article on backtesting without overfitting for more on this point.

Backtrex calculates the MAE of each trade by scanning OHLC data candle by candle between the entry and exit moment of the position. For each long trade, it records the minimum price reached and calculates the pullback as a percentage from the entry price. For a short trade, it records the maximum price. This calculation happens automatically during backtest execution, without any external data manipulation.

Suggested Reads

Ready to backtest your strategies?

Join the waitlist and be the first to build, test, and validate trading strategies — no coding required.

Create your free account in 30 seconds. No credit card required.