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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Data | Any | Yes | — | Price data as an M-by-4 matrix, table, or timetable. |
Returns
| Name | Type | Description |
|---|---|---|
MACDLine | Any | Moving Average Convergence/Divergence series. |
SignalLine | Any | Nine-period exponential moving average of the MACD line. |
Returned values from macd depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:macd:InvalidInput | Input is not a numeric M-by-4 matrix or table/timetable with High, Low, Open, and Close variables. | macd: invalid input |
RunMat:macd:OutputCount | More than two output arguments are requested. | macd: too many output arguments |
RunMat:macd:Internal | Output 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.
Related Finance functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how macd is executed, line by line, in Rust.
- View the source for macd in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.