Discussing the article: "Meta-Labeling the Classics (Part 4): Filtering and Sizing MACD Trades"

 

Check out the new article: Meta-Labeling the Classics (Part 4): Filtering and Sizing MACD Trades.

MACD signal-line crossovers often reflect range noise rather than true momentum shifts, producing whipsaws. We apply a two-layer meta-labeling pipeline with an Optuna-optimized regime gate to filter entries on EURUSD H1, turning a gross-losing rule into a positive but not statistically significant track. A secondary Random Forest adds no lift due to too few gated samples, clarifying when filtering helps and when the ML layer is data-starved.

Gerald Appel's original MACD uses three EMA spans — 12, 26, and 9 periods — chosen against weekly stock charts in the 1970s. Nothing in the construction adapts those spans, or the signal-line crossover rule itself, to a specific instrument or a specific bar frequency. Applied unmodified to EURUSD H1 data, the rule generates a trade on every sign change of MACD − Signal, with no requirement that the change be large, sustained, or aligned with any broader context.

The panel below shows a real segment from the dataset used in this article: 43,103 hourly EURUSD bars from January 2018 through December 2024. The data comes from a broker export with bid, ask, and mid OHLC, plus spread and tick volume. Mid prices are used for signals, features, and labeling; Section 6 provides the full description. From August 20 to August 23, 2019, price chops inside a roughly 90-pip band before breaking sharply higher in the final hours shown. The MACD and signal lines cross seventeen times in this window — nine long, eight short — each crossover triggering a trade in the opposite direction from the one before it.

from afml.strategies.trading_strategies import MACDStrategy

strat = MACDStrategy()  # fast=12, slow=26, signal=9 (Appel's defaults)
macd_df = strat.compute_macd(df)      # columns: macd, macd_signal, macd_hist
raw_signals = strat.generate_signals(df)  # 1 / -1 / 0, signal-line crossovers only

MACD signal-line crossovers during a ranging stretch

Author: Patrick Murimi Njoroge