UTC

Sign up free

MACD Strategy: Writing Crossovers, the Zero Line and Divergence as Quant Rules

Three ways to turn MACD into quant rules: signal line crossovers, a zero-line filter and histogram momentum. Rules, pitfalls and a MetisAI backtest prompt.

What MACD is made of

MACD line (DIF) = 12-period EMA − 26-period EMA; the signal line (DEA) is the 9-period EMA of the MACD line; histogram = MACD line − signal line (some software multiplies it by 2). At its core it’s a smoothed difference between moving averages, which makes it a trend and momentum indicator.

Three ways to write it as quant rules

  1. Crossover: go long when the MACD line crosses above the signal line, and close when it crosses below. Lots of signals, and lots of noise.
  2. Zero-line filter: only accept bullish crossovers when the MACD line is above zero, which filters out bounce signals inside a downtrend.
  3. Histogram momentum: enter when the histogram turns from negative to positive, or grows for N bars in a row.

Divergence (price makes a new high while MACD doesn’t) is popular in discretionary trading, but it’s hard to write as a strict rule, and backtests can easily end up relying on subjective judgment. Beginners shouldn’t start with it.

One-sentence prompt

Prompt: copy it straight into MetisAI

On BTC/USDT 4-hour candles, use MACD(12,26,9): only when the MACD line (DIF) is above 0, go long when the MACD line crosses above the signal line (DEA); close the position when the MACD line crosses below the signal line. Stop loss of 4% per trade. Compare the backtest results with and without the zero-line filter.

Note

This article only explains how tools are used and how strategies work. It is not investment advice. Backtest and paper trading performance does not represent future returns. Digital assets and leveraged trading carry extremely high risk; only use money you can afford to lose.

+

Related reading

  1. 01Moving Average Crossover Strategy: How It Works, Choosing Parameters, and a One-Sentence AI Backtest PromptGo long on a golden cross, exit on a death cross. The most classic trend strategy, and the best one to backtest first.
  2. 02RSI Overbought/Oversold Strategy: The Go-To Starting Point for Mean ReversionBuy when oversold, sell when it returns to the middle. High win rate, but it must have a stop loss.
  3. 03Bollinger Bands Strategy: Two Ways to Trade It — Reversion and BreakoutOne indicator, two opposite uses. What matters is whether the market is ranging or building up to a breakout.