DNS Research. Trading and Investing Blog. Free articles every day.

How to Backtest a Trend Following Strategy Without Fooling Yourself

advertisement

Define the Strategy With Zero Discretion Before Touching Data

A trend following strategy that lives only in your head is not a strategy; it is a mood. Before you load a single price series, write down every rule in plain language with no room for interpretation. Entry trigger: “Buy when the 50-day simple moving average crosses above the 200-day simple moving average.” Exit trigger: “Sell when the 20-day low is breached on a closing basis.” Position sizing: “Risk 0.5% of equity per trade, calculated from the distance between entry price and the 2×ATR(14) stop.” Universe: “The 20 most liquid futures contracts by average daily dollar volume, rebalanced annually.” Timeframe: “Daily bars, adjusted for continuous contract roll.” If any sentence contains “I’ll decide then” or “if it looks strong,” delete it. Discretionary overrides are the primary vector for self-deception. A backtest of a vague rule set measures your ability to rationalize, not the edge of a trend following system. Document the exact version number of your rules. When you later change the 50-day moving average to a 40-day because the equity curve “feels smoother,” you have created a new strategy and invalidated every prior test. Version control is not bureaucracy; it is the difference between research and wishful thinking.

Use Point-in-Time Data, Not the Cleaned Hindsight Version

Most free historical price data contains survivorship bias, look-ahead bias, and backfill contamination. Survivorship bias: if your universe excludes delisted futures contracts, you are testing only the winners. A trend following strategy that shorted crude oil in 2020 would have been stopped out repeatedly if you include the April 2020 negative price event; excluding that contract because it “later recovered” is cheating. Look-ahead bias: using a closing price to trigger an entry that you could only have known after the close, then executing at that same close. In reality, you execute at the next open or with slippage. Backfill bias: data vendors often add historical prices for contracts that were illiquid at the time, making them appear tradable when they were not. Purchase point-in-time data from a reputable source such as CSI, Norgate, or Bloomberg with historical constituents. For equities, use CRSP or Compustat with delisting returns. For crypto, use exchange-native data with timestamps in UTC and no later revisions. If you cannot afford point-in-time data, restrict your backtest to the most liquid instruments that existed for the entire period and manually verify that each contract had sufficient volume on each signal date. A trend following strategy tested on survivorship-biased data will show a Sharpe ratio 0.3 to 0.8 higher than reality. That difference is not alpha; it is a data artifact.

Model Execution Costs With Brutal Realism

Trend following strategies trade infrequently, but when they do, they often trade in the direction of momentum—meaning you buy after prices have risen and sell after they have fallen. This is the opposite of providing liquidity. You are a liquidity taker. Your backtest must include:

  • Commission per contract or per share: Use your broker’s actual schedule, not zero-commission fantasy. For futures, $2.50 per side per contract is realistic. For equities, $0.005 per share plus SEC fees.
  • Slippage: For liquid futures like ES or CL, assume one tick of slippage per side. For less liquid contracts like KC or SB, assume two to three ticks. For small-cap equities, assume 10 to 30 basis points of market impact per side.
  • Market impact: If your position size exceeds 1% of average daily volume, add a square-root impact model: impact = 0.1 × (your volume / ADV)^0.5 × daily volatility. This prevents the backtest from assuming you can move $50 million into a thin contract with no price concession.
  • Roll costs: Continuous futures contracts require rolling from front month to next month. The roll yield can be positive or negative. Do not use a back-adjusted series that smooths away roll gaps. Instead, simulate the actual roll: exit the front month, enter the next month, pay commission and slippage on both legs. For a trend following strategy that holds positions for months, roll costs can consume 10–20% of gross profits.
  • Borrow costs for shorts: If you short equities or ETFs, include stock borrow fees. For hard-to-borrow names, fees can exceed 50% annualized.

Run your backtest with zero costs, then with your best estimate, then with triple your best estimate. If the strategy only works with zero costs, it is not a strategy; it is a spreadsheet error. A robust trend following system should survive costs that are 50% higher than your realistic estimate.

Avoid Overfitting by Limiting Parameters and Using Walk-Forward Analysis

Overfitting is the process of finding a pattern that exists only in your historical sample. Trend following strategies are particularly vulnerable because they have few parameters, and traders often tweak those parameters until the equity curve looks like a straight line. The cure is not more complex optimization; it is fewer degrees of freedom and out-of-sample testing.

Rule 1: Use no more than three parameters. A typical trend following system has: lookback period for entry (e.g., 50 days), lookback period for exit (e.g., 20 days), and risk per trade (e.g., 0.5%). That is three. If you add a volatility filter, a seasonality filter, and a correlation filter, you now have six parameters. With six parameters, you can fit noise. With three, you cannot.

Rule 2: Walk-forward analysis. Divide your data into an in-sample period (e.g., 1990–2005) and an out-of-sample period (2006–2010). Optimize parameters on the in-sample period. Then freeze those parameters and test on the out-of-sample period. Then roll forward: optimize on 1991–2006, test on 2007–2011. Repeat until you have at least 10 out-of-sample windows. The average out-of-sample performance is your realistic expectation. If the out-of-sample Sharpe ratio is less than half the in-sample Sharpe ratio, your strategy is overfit. Walk-forward analysis is not perfect—it still assumes that the future resembles the past—but it is the minimum standard for serious backtesting.

Rule 3: Parameter sensitivity. After walk-forward analysis, test your chosen parameters plus or minus 20%. If a 50-day moving average works but a 45-day or 55-day moving average loses money, you have fit a spike. A robust trend following strategy should show a plateau: 40, 50, 60, and 70-day moving averages should all produce similar results. If they do not, you are curve-fitting.

Rule 4: Do not re-optimize after seeing out-of-sample results. This is the cardinal sin. Once you test on out-of-sample data, that data is no longer out-of-sample. If you change parameters and re-test, you have contaminated your only honest estimate. Lock your parameters, then paper trade for six months before risking capital.

Account for Regime Changes and Non-Stationarity

Financial markets are not stationary. The trend following edge that worked in the 1970s commodity boom, the 1980s dollar trend, the 1990s equity bull market, and the 2000s commodity supercycle may not work in the 2020s. A backtest that spans 50 years and shows a smooth equity curve is lying to you. You must decompose performance by regime:

  • Trending vs. mean-reverting regimes: Use the Hurst exponent or the autocorrelation of returns to classify each month. Trend following works when the Hurst exponent is above 0.5. If your backtest shows profits only in trending regimes, that is fine—but you must accept that you will lose money in mean-reverting regimes. Size your positions accordingly.
  • Interest rate regimes: Trend following in bonds behaves differently when rates are rising versus falling. Test your strategy separately for 1980–2000 (falling rates) and 2000–2020 (mixed). If it only works in falling-rate environments, you have a hidden duration bet.
  • Volatility regimes: Trend following tends to perform well when volatility is rising from low levels. It suffers when volatility spikes and then mean-reverts quickly. Use a volatility filter—but not as an optimization parameter. Simply observe: does your strategy lose money when VIX is above 40? If so, reduce position size in high-volatility regimes.
  • Liquidity regimes: The 2008 financial crisis and the March 2020 COVID crash saw liquidity evaporate. Your backtest must include those periods with realistic slippage. If your strategy would have been unable to exit positions, the backtest is fiction.

Non-stationarity means that past performance is not even a rough guide to future performance. The best you can do is build a strategy that has a logical reason to work (trends persist due to behavioral underreaction and institutional herding) and that has survived many different regimes with modest drawdowns.

Stress Test With Monte Carlo and Bootstrap Methods

A single historical backtest is one path through a stochastic process. You need to know the distribution of possible outcomes. Use two methods:

Trade-level bootstrap: Extract the list of all trades (entry date, exit date, return). Randomly resample with replacement to create 10,000 new equity curves. Calculate the 5th percentile of final equity, the median, and the 95th. If the 5th percentile is a 50% drawdown, you must be prepared for that. If the 5th percentile is ruin (equity below zero), your position sizing is too aggressive.

Block bootstrap: Resample blocks of consecutive days (e.g., 20-day blocks) to preserve autocorrelation. This is more realistic for trend following because trends cluster. A simple trade-level bootstrap destroys the serial correlation that is the source of your edge. Block bootstrap will show wider drawdowns and lower Sharpe ratios. Use the block bootstrap results for risk management.

Monte Carlo with parameter perturbation: Randomly vary your three parameters by ±10% and re-run the backtest 1,000 times. Plot the distribution of Sharpe ratios. If the 5th percentile Sharpe ratio is negative, your strategy is fragile. If the 5th percentile is still above 0.5, you have a robust edge.

Stress test specific historical scenarios: What happens if 2008 happens again? What if 2020 happens again? What if a 1987-style one-day crash happens? Run your strategy through those exact price paths with your current rules. If a single day can wipe out 40% of your equity, your stop losses are not working as intended. Trend following stops are usually wide, so a gap through your stop can cause large losses. Model gap risk: assume that on any given day, the market can gap 10% against you. Does your position sizing survive?

Validate With Paper Trading and Small Live Capital

Backtesting is necessary but not sufficient. The final filter is live execution. Paper trade your exact rules for at least three months. Record every signal, every fill, every slippage event. Compare your paper trading results to the backtest’s predictions for the same period. If the backtest says you should have made 5% and you made 2%, investigate: Was slippage higher? Did you miss a signal because you were on vacation? Did you override a rule because “this time felt different”? Those overrides are the fooling-yourself mechanism.

After paper trading, allocate small live capital—1% of your intended eventual size. Trade for six months. The goal is not to make money; the goal is to measure the gap between backtest and reality. A typical gap for a well-designed trend following strategy is 20–30% of gross profits lost to execution and behavioral errors. If your gap is larger, fix your process before scaling.

Document Every Assumption and Bias You Can Identify

Keep a backtest journal. For every test, write down:

  • Data source and version
  • Exact rules with version number
  • Cost assumptions (commission, slippage, roll, borrow)
  • In-sample and out-of-sample periods
  • Parameter values and why you chose them
  • Any discretionary decisions you made during the test
  • Results: CAGR, Sharpe, max drawdown, win rate, average win/loss, number of trades
  • Biases you know are present: survivorship, look-ahead, overfitting, regime-specific

Then ask a colleague to review your journal and try to break your backtest. The best way to avoid fooling yourself is to have someone else try to fool you. If they find a bias you missed, fix it and re-run. If they cannot find a bias after two hours of trying, you have a reasonably clean backtest.

Reject Any Strategy That Requires Perfect Conditions

A trend following strategy that only works when:

  • Volatility is between 10% and 20%
  • Interest rates are falling
  • The dollar is weakening
  • Commodities are in backwardation
  • You have zero slippage
  • You never miss a signal

…is not a strategy. It is a fantasy. A real trend following edge survives imperfect conditions: higher costs, lower liquidity, unexpected gaps, and regime shifts. If your backtest shows a 2.0 Sharpe ratio with zero costs and a 0.3 Sharpe ratio with realistic costs, the edge is in the costs, not the trend. Reject it. Start over with simpler rules, fewer parameters, and wider stops. The goal is not to maximize backtest performance; the goal is to build a system that you can execute for 20 years without blowing up. That system will have a lower backtest Sharpe ratio than the overfit alternatives. That is the price of honesty. Pay it.

advertisement

latest posts

Something went wrong. Please refresh the page and/or try again.

Discover more from DNS Research

Subscribe now to keep reading and get access to the full archive.

Continue reading