MACD zero-line cross, long when above, exit when below
Buy when the MACD line crosses above zero and sell when it crosses back below zero.
Killed by costs
There is something there before trading costs; after them, too little is left to count (under 0.04R a trade).
- +0.069R a trade before costs, −0.006R after the spread and the selection haircut.
42 large US stocks, 15 years
Before costs +0.069R
By trade and by day, sized to a first try
What the numbers say
Across 1395 laggard trades the idea made 0.069R a trade before costs and −0.006R after costs. In bull markets it came to −0.038R and in flat markets −0.028R; the bear-market result was 0.273R (t 2.97). The after-cost result for laggards is below zero, which is why the verdict is killed by costs.
How it was tested
Buy at the close when the MACD line crosses from below to above zero, and exit at the close when it crosses back below zero.
- Side
- Long
- Its own exit
- Exit at the close of the first day after entry where the MACD line (12,26) crosses back below zero: MACD line < 0 today and >= 0 the previous day., checked at each close
- Time limit
- Exit at the close after 30 trading days, unless the stop, the target or its own exit comes first
- Bar to clear
- t > 2.01, by trade and by day, sized to a first try (one idea, tested once)
- Prices
- 15 years of daily bars through 2026-11-20; judged 2026-11-22
- MACD uses the conventional 12/26 EMA settings; the 9-period signal line is not used
- Zero-line crossing is judged on the MACD line from daily closes
- Entry is at the close of the signal day
- The idea names no stop or target, so a wide 3 x ATR(14) stop and 6 x ATR(14) target are protective choices
- The idea names no time limit, so the maximum of 30 trading days is used as a backstop
- Only the long side is tested; selling is taken as exiting the long, not shorting
The evidence
The laggards decide: 22 large stocks that lagged or fell, where hindsight can't flatter a rule. Today's winners sit beside them to show what survivorship would add.
| Market | Trades | Per trade | t, by trade | t, by day | Random dates | Winners, per trade |
|---|---|---|---|---|---|---|
| Bull | 1,022 | −0.038R | −1.15 | −1.61 · 778d | −0.025R · beats 45% | +0.137R |
| Flat | 240 | −0.028R | −0.46 | −0.06 · 183d | −0.060R · beats 75% | +0.262R |
| Bear | 133 | +0.273R | 2.97 | 2.58 · 102d | +0.159R · beats 95% | +0.297R |
| All | 1,395 | −0.006R | −0.013R | +0.175R |
R is the result per trade in units of the risk taken (entry to stop). Costs are each stock's own trading spread (median 13.3 bps) plus 0.045R for the fills a real order wouldn't get. “By day” groups trades opened the same day, so a rule that fires on the same dates for every stock counts as a few events. “Random dates” places the same plan on random days of the same stocks in the same kind of market, 20 times; the idea must beat 95% of those draws.
The scanner we wroteShow the codeHide
from decimal import Decimal
import math
from core.domain import Bar
from strategies.indicators import atr
from scanners.base import Candidate
def _ema_series(values, n):
out = [None] * len(values)
if len(values) < n:
return out
seed = sum(values[:n]) / n
out[n - 1] = seed
k = 2.0 / (n + 1)
prev = seed
for i in range(n, len(values)):
prev = values[i] * k + prev * (1 - k)
out[i] = prev
return out
class MacdZeroLineCrossLong:
name = "macd_zero_line_cross_long"
description = "Long when MACD(12,26) line crosses above zero; exit when it crosses back below zero."
def __init__(self, fast: int = 12, slow: int = 26, atr_period: int = 14,
stop_mult: float = 3.0, target_mult: float = 6.0) -> None:
self._fast = fast
self._slow = slow
self._atr_period = atr_period
self._stop_mult = stop_mult
self._target_mult = target_mult
def _macd_last_two(self, bars):
if len(bars) < self._slow + 1:
return None
closes = [float(b.close) for b in bars]
ef = _ema_series(closes, self._fast)
es = _ema_series(closes, self._slow)
if ef[-1] is None or es[-1] is None or ef[-2] is None or es[-2] is None:
return None
today = ef[-1] - es[-1]
prev = ef[-2] - es[-2]
if math.isnan(today) or math.isnan(prev):
return None
return prev, today
def scan(self, ticker: str, bars: list[Bar]) -> Candidate | None:
if len(bars) < max(self._slow + 1, self._atr_period + 1):
return None
pair = self._macd_last_two(bars)
if pair is None:
return None
prev, today = pair
if not (today > 0 and prev <= 0):
return None
atr_val = atr(bars, self._atr_period)
if atr_val is None or atr_val <= 0:
return None
atr_dec = Decimal(str(atr_val))
entry = bars[-1].close
stop = entry - Decimal(str(self._stop_mult)) * atr_dec
target = entry + Decimal(str(self._target_mult)) * atr_dec
risk = entry - stop
if risk <= 0 or stop <= 0:
return None
rr = (target - entry) / risk
return Candidate(
ticker=ticker,
side="buy",
entry=entry,
stop=stop,
target=target,
risk_reward_ratio=rr.quantize(Decimal("0.01")),
signal_strength=50,
thesis="MACD(12,26) line crossed from at/below zero to above zero at the close.",
)
def exit_now(self, ticker: str, bars: list[Bar], entry: Decimal,
side: str, bars_held: int) -> bool:
if side != "buy":
return False
pair = self._macd_last_two(bars)
if pair is None:
return False
prev, today = pair
return today < 0 and prev >= 0
Hypothetical results from our own backtest of the rule as restated, on 42 large US stocks over 15 years. Past performance, real or simulated, does not predict future results. Research and education only; not investment advice.
Describe it in plain words and get the same honest test in about a minute.