Strategy · Trend following

MACD.

Long while the MACD line is above its signal line, short while it is below: a smoothed trend signal.

The rule

  1. The MACD line is the fast exponential average of the close minus the slow one; the signal line is an exponential average of the MACD line.
  2. Long while the MACD line is above the signal line, short while it is below.
  3. Flat for the first slow-window days, while the averages still mostly reflect the starting price.

It holds the crossover state rather than trading only on the day of the crossing, so it is always in the market once warmed up, and its position series can be compared day by day with momentum's.

Every signal is acted on at the next day's close, never the close it was computed from. Skipping that one-day shift is the most common way a backtest invents returns (why).

Parameters

ParameterDefaultWhat it does
Fast average12 daysSpan of the faster exponential average.
Slow average26 daysSpan of the slower one, and the warm-up.
Signal line9 daysSpan of the average of the MACD line.

What validation tries

Walk-forward validation picks the best of these 4 combinations on the first 70% of the period, then scores only that one on the remaining 30%. The fewer combinations, the less room to find one that fit by luck.

  • 8 / 17 / 9
  • 12 / 26 / 9
  • 16 / 34 / 9
  • 19 / 39 / 9

How it did on AAPL

From the write-up: the same three strategies on Apple, 10 bp costs, with the 70/30 split. The best in-sample combination on the first window was 16 / 34 / 9. Moving the end date one year moves the split, and the verdict can flip.

Test period endsIn-sample SharpeOut-of-sample SharpeVerdict
2023 (2018–2024 run)0.511−0.300failed
2024 (2018–2025 run)0.656−0.114failed

Hypothetical results on past data, re-run by a script in the repository. Not a recommendation to trade this or any strategy.

Where it misleads

Being always in the market means paying for every flip between long and short, so costs matter more here than for the other two. And with only four combinations to choose from it looks hard to overfit, yet on the later AAPL window the probability that its in-sample pick was overfit came out at 0.77.

More on reading a result like this: how to tell if a backtest is overfit.

Run it yourself

The same set-up, AAPL from 2018 to 2024, opens in the workspace with this strategy's defaults, straight after sign-up if you are new. Change the ticker or the dates and the Validate tab runs the same checks.

The same rule on other stocks: 39 US and Indian stocks. The other strategies: Momentum · Bollinger. Head to head: Momentum vs MACD · MACD vs Bollinger bands.