macd — Compute the Moving Average Convergence/Divergence indicator.

macd(Data) computes the 12-period minus 26-period exponential moving-average line and the 9-period exponential signal line.

Syntax

MACDLine = macd(Data)
[MACDLine, SignalLine] = macd(Data)

Inputs

NameTypeRequiredDefaultDescription
DataAnyYesPrice data as an M-by-4 matrix, table, or timetable.

Returns

NameTypeDescription
MACDLineAnyMoving Average Convergence/Divergence series.
SignalLineAnyNine-period exponential moving average of the MACD line.

Returned values from macd depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:macd:InvalidInputInput is not a numeric M-by-4 matrix or table/timetable with High, Low, Open, and Close variables.macd: invalid input
RunMat:macd:OutputCountMore than two output arguments are requested.macd: too many output arguments
RunMat:macd:InternalOutput construction fails.macd: internal error

How macd works

  • Matrix input must be M-by-4 with High, Low, Open, and Close prices in columns 1 through 4.
  • Table and timetable inputs must contain High, Low, Open, and Close variables, matched case-insensitively.
  • Table and timetable High, Low, Open, and Close variables must be numeric M-by-1 vectors.
  • The returned MACDLine and SignalLine preserve the input row count and container type.
  • For table and timetable inputs, outputs contain a Close variable with the computed series.
  • Empty M-by-4 inputs return empty M-by-1 outputs; NaNs propagate through the exponential moving-average recurrence.

Example

Compute MACD and signal line

[m,s] = macd(priceData)

Using macd with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how macd changes the result.

Run a small macd example, explain the result, then change one input and compare the output.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how macd is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.