TA.MACD
Calculates the Moving Average Convergence Divergence (MACD) indicator.
TA.MACD(inReal)
TA.MACD(inReal, optInFastPeriod, optInSlowPeriod, optInSignalPeriod)Examples
Compute MACD(12,26,9) on 15-minute K-lines.
javascript
function main() {
var records = exchange.GetRecords(PERIOD_M15)
if (!records) return
var macd = TA.MACD(records, 12, 26, 9)
Log("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2])
// Output: DIF: [...] DEA: [...] MACD: [...], three arrays each as long as the K-lines
}
python
def main():
records = exchange.GetRecords(PERIOD_M15)
if not records:
return
macd = TA.MACD(records, 12, 26, 9)
Log("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2])
# Output: DIF: [...] DEA: [...] MACD: [...], three arrays each as long as the K-lines
rust
fn main() {
let Ok(records) = exchange.GetRecords(None, PERIOD_M15, None) else { return };
let macd = TA.MACD(&records, 12, 26, 9);
Log!("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2]);
// Output: DIF: [...] DEA: [...] MACD: [...], three arrays each as long as the K-lines
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | K-line (candlestick) data. |
optInFastPeriod | number | No | Fast line period. |
optInSlowPeriod | number | No | Slow line period. |
optInSignalPeriod | number | No | Signal line period. |
See Also
Remarks
FMZ Quant's TA indicator library optimizes the algorithms of commonly used indicators and supports calls from JavaScript, Python, and Rust strategies. For details, see the open-source TA library code.
The default values of the optInFastPeriod, optInSlowPeriod, and optInSignalPeriod parameters of the TA.MACD() function are 12, 26, and 9 respectively.
The histogram MACD = DIF - DEA (not multiplied by 2). The EMA is seeded with the simple average of the first period bars, so the warm-up period is NaN (None in Python).