# MACD

Use the [shared role, Reverse and timing rules](../05-signal-passports.md). Let A=fast EMA(close) minus slow EMA(close), B=the signal EMA of A, and h=A−B. `fp`, `sp` and `sgp` select these three periods; defaults are 12/26/9. Each is an integer 2…50. The confirmed checks do not require fp<sp; numerical compatibility across calculation paths for fp>sp remains unconfirmed, so do not present a reversed-period example as validated numerical transfer.

## Entry — macd.entry

`ec` selects one of four events. Evaluate the L branch first:

- `CSM`: `A1<B1` and `A0>=B0` gives L; `A1>B1` and `A0<=B0` gives S; otherwise N.
- `CMZL`: `A1<0` and `A0>=0` gives L; `A1>0` and `A0<=0` gives S; otherwise N.
- `BGH`: `h0>=0`, `h1<h0`, and not `(h1>=0 and h2<h1)` gives L. `h0<0`, `h1>=h0`, and not `(h1<0 and h2>=h1)` gives S. Otherwise N.
- `BDH`: `0>h0>h1` and not `(0>h1>h2)` gives L. `0<=h0<=h1` and not `(0<=h1<=h2)` gives S. Otherwise N.

BGH/BDH require three values and exclude continuation of the immediately preceding qualifying state. Neither is simply “histogram positive/negative”. For CSM, previous `(A=.8,B=1)`, current `(A=1.1,B=1.1)` gives L; previous equality followed by A>B does not.

## Filter — macd.filter

`ft` selects a current relationship or change, not an entry event:

- `BD`: A0>B0 gives IS; A0<B0 gives IL; equality gives AA; otherwise N.
- `BZL`: A0<0 and B0<0 gives IS; A0>0 and B0>0 gives IL; otherwise N. Touching zero does not qualify.
- `BGDM`: A0>A1 gives IS; A0<A1 gives IL; equality gives AA; otherwise N.
- `BGDS`: the same rule for B0 versus B1.
- `BGDH`: h0>h1 and h0>0 gives IS; h0<h1 and h0<0 gives IL; h0==h1==0 gives AA; otherwise N. Flat nonzero histogram is not the AA case here.

## Exit — macd.exit

Select the same CSM/CMZL/BGH/BDH predicate with cba. ED/EDOP acts on the opposite directional signal after Reverse; AVG acts on the own-side signal. The five filter states are not alternative exit events.

## Definition coverage and observed controls

The controls below identify this dated schema. Their exact labels, value types and context overrides are in the catalogue. Any omitted standard selector must not be added manually.

- `macd.entry` — `MAIN` / `MACD`. Semantics: **Entry — macd.entry**. Fields: `ss`, `Is`, `ct`, `at`, `rs`, `fp`, `sp`, `sgp`, `ec`. timeframe: ID-specific list; default 1m; candles: DEFAULT/HEIKEN_ASHI; default DEFAULT; calculation: CL/CR; default CL; Reverse: available; default false.
- `macd.exit` — `CLOSE_BY` / `MACD`. Semantics: **Exit — macd.exit**. Fields: `ss`, `Is`, `ct`, `at`, `rs`, `cba`, `fp`, `sp`, `sgp`, `ec`. timeframe: ID-specific list; default 1m; candles: DEFAULT/HEIKEN_ASHI; default DEFAULT; calculation: CL/CR; default CL; Reverse: available; default false.
- `macd.filter` — `PRICE_LIMIT` / `MACD_PRICE_LIMIT`. Semantics: **Filter — macd.filter**. Fields: `ss`, `Is`, `ct`, `at`, `rs`, `pla`, `fp`, `sp`, `sgp`, `ft`. timeframe: ID-specific list; default 1m; candles: DEFAULT/HEIKEN_ASHI; default DEFAULT; calculation: CL/CR; default CR; Reverse: available; default false.
