MACD

The MACD shows the relationship between two moving averages of the price to identify trend changes.

Role in the strategy

SlotAvailableRole
Entry PointNo—
Entry RuleYesFilters entries by the MACD line direction or its zero position.
Exit PointNo—
Exit RuleYesTriggers exits by the MACD line direction or its zero position.

The MACD produces conditions, not order prices. As an entry rule it is ANDed with the entry point and the other entry rules; as an exit rule it is ORed with the other exit rules. See Indicators for the slot semantics.

Logic rules

RuleLong signal is 1 whenShort signal is 1 when
MACD line risesMACD line rose on the previous barMACD line fell on the previous bar
MACD line fallsMACD line fell on the previous barMACD line rose on the previous bar
MACD line is higher than the Zero lineMACD line is above 0MACD line is below 0
MACD line is lower than the Zero lineMACD line is below 0MACD line is above 0
MACD line crosses the Zero line upwardMACD line crossed above 0 from belowMACD line crossed below 0 from above
MACD line crosses the Zero line downwardMACD line crossed below 0 from aboveMACD line crossed above 0 from below
MACD line changes its direction upwardMACD line formed a valley (down then up)MACD line formed a peak (up then down)
MACD line changes its direction downwardMACD line formed a peak (up then down)MACD line formed a valley (down then up)

Parameters

ParameterTypeDefaultRangePurpose
Apply toselectCloseOpen, High, Low, Close, Median, Typical, WeightedPrice series the MACD is calculated from
Fast EMAnumber122 to 1000Period of the fast exponential average
Slow EMAnumber262 to 1000Period of the slow exponential average
MACD SMAnumber92 to 1000Period of the signal line

Calculation

tech.MACD and tech.MACDSignal in engine/indicator-engine/tech.ts compute:

  • MACD line = Fast EMA − Slow EMA of the selected price series.
  • Signal line = simple moving average of the MACD line over MACD SMA bars.

The MACD line is drawn as bars and the Signal line as a dotted line in a separate chart pane. The rules use the MACD line against the 0 / 0 level pair.

Backtesting

  • The rule is evaluated on the previous (closed) bar with the standard dead zone (SIGMA = 0.000001).
  • The MACD contributes only long/short signal arrays — it never changes the entry or exit order price.
  • An entry happens only when the entry point allows the direction and every entry rule passes; an exit happens when the exit point is reached and any exit rule passes.