Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
TA.MACD
TA.KDJ
TA.RSI
TA.ATR
TA.OBV
TA.MA
TA.EMA
TA.BOLL
TA.Alligator
TA.CMF
TA.Highest
TA.Lowest
TA.SMA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

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

TypeDescription

array

The return value of the TA.MACD() function is a two-dimensional array with the structure: [DIF, DEA, MACD].

Arguments

NameTypeRequiredDescription

inReal

Record array / numeric array

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).