Maybe you could use talib-binding to do this, I wrote it yesterday. The code as follow:

import * as talib from 'talib-binding'
talib.MACD([106.2199999999999989,
    112.6500000000000057,
    115.0100000000000051,
    116.5000000000000000,
    117.1599999999999966,
    116,
    115.1500000000000057,
    115.2399999999999949,
    113.5498999999999938,
    119.6901000000000010,
    115.5199999999999960,
    115.1700000000000017,
    115.4000000000000057,
    114.6400000000000006,
    118.4350000000000023,
    121.4599999999999937,
    122.3700000000000045,
    122.9899999999999949,
    123.3199999999999932,
    122.8900000000000006,
    124.4800000000000040,
    125.1599999999999966,
    125.2199999999999989,
    130.7500000000000000,
    132.0699999999999932], 8, 17, 9)

The result is:

[ [ 3.8371737131517705 ],
    [ 2.7731844591512465 ],
    [ 1.063989254000524 ] ]
Answer from acrazing on Stack Overflow
🌐
CanvasJS
canvasjs.com › home › javascript stockcharts › javascript stockchart with macd - moving average convergence divergence indicator
JavaScript Stock Charts with MACD Indicator | CanvasJS
December 5, 2022 - window.onload = function () { var dps1 = [], dps2= []; var stockChart = new CanvasJS.StockChart("chartContainer",{ theme: "light2", title:{ text:"Technical Indicators: MACD" }, subtitles: [{ text: "Moving Average Convergence Divergence" }], charts: [{ legend: { verticalAlign: "top", horizontalAlign: "left" }, axisX: { tickLength: 0, lineThickness: 5, labelFormatter: function(e) { return ""; } }, axisY: { prefix: "$" }, data: [{ type: "candlestick", name: "Stock Price", yValueFormatString: "$#,###.##", dataPoints : dps1 }], }], navigator: { data: [{ dataPoints: dps2 }], slider: { minimum: new D
🌐
DEV Community
dev.to › onurcelik › calculating-the-moving-average-convergence-divergence-macd-with-javascript-44j
Calculating the Moving Average Convergence Divergence (MACD) with JavaScript - DEV Community
December 19, 2022 - Here's an example of how you can implement these formulas to calculate the MACD for a given array of closing prices: function calculateMACD(closingPrices) { const ema12 = calculateEMA(closingPrices, 12); const ema26 = calculateEMA(closingPrices, 26); const macd = ema12 - ema26; return macd; } function calculateEMA(closingPrices, period) { const k = 2 / (period + 1); let ema = closingPrices[0]; for (let i = 1; i < closingPrices.length; i++) { ema = (closingPrices[i] * k) + (ema * (1 - k)); } return ema; } // Example usage const closingPrices = [100, 110, 105, 115, 120, 130, 140, 150, 145, 155]; const macd = calculateMACD(closingPrices); console.log(macd); // Output: -1.33
🌐
GitHub
github.com › kaelzhang › macd
GitHub - kaelzhang/macd: FinTech utility to calculate MACD, the Moving Average Convergence / Divergence.
The performance of stock-pandas is many times higher than JavaScript libraries, and can be directly used by machine learning programs. FinTech utility to calculate MACD.
Starred by 26 users
Forked by 7 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Medium
medium.com › @onurcelik.dev › calculating-macd-moving-average-convergence-divergence-with-javascript-19788e0ffb62
Calculating MACD (Moving Average Convergence Divergence) with JavaScript — Updated 2025 | by Mustafa Onur Çelik | Medium
August 30, 2025 - function exponentialMovingAverage(prices, period) { const alpha = 2 / (period + 1); const ema = []; // Start with a simple moving average for the first EMA value let sma = prices.slice(0, period).reduce((sum, val) => sum + val, 0) / period; ema[period - 1] = sma; // Continue with EMA calculation for (let i = period; i < prices.length; i++) { sma = prices[i] * alpha + sma * (1 - alpha); ema[i] = sma; } return ema; } function calculateMACD(prices) { const ema12 = exponentialMovingAverage(prices, 12); const ema26 = exponentialMovingAverage(prices, 26); const macdLine = prices.map((_, i) => ema12[i] !== undefined && ema26[i] !== undefined ?
🌐
npm
npmjs.com › search
keywords:macd - npm search
🚀 Comprehensive n8n node collection for financial analysis and automation. Features 55+ technical indicators (RSI, MACD, Bollinger Bands), 32+ candlestick patterns (Doji, Hammer, Engulfing), derivative statistics (Open Interest, Funding Rate, Long/Short
🌐
npm
npmjs.com › package › macd
macd - npm
FinTech utility to calculate MACD, the Moving Average Convergence / Divergence.. Latest version: 1.0.4, last published: 5 years ago. Start using macd in your project by running `npm i macd`. There are 1 other projects in the npm registry using macd.
      » npm install macd
    
Published   Mar 02, 2021
Version   1.0.4
Author   kaelzhang
🌐
Syncfusion
ej2.syncfusion.com › domain url › documentation › stock chart › technical indicators
Technical indicators in EJ2 TypeScript Stock chart control | Syncfusion
MACD histogram is used to differentiate MACD line and signal line. RSI shows how strongly a stock is moving in its current direction. To render a RSI Indicator, use indicator type as Rsi and inject RsiIndicator module using StockChart.Inject(Rsindicator).RSI indicator will be represented by three lines (upperBand, lowerBand, signalLine). The upperBand and lowerBand values are customized by overBought and overSold properties of indicator and the signalLine is calculated by RSI formula.
🌐
Jenscript
jenscript.io › jenscript › charts › samples › stock › 6
JavaScript Stock Chart - MACD
May 24, 2015 - var minor = { tickMarkerSize : 2, tickMarkerColor : '#9b59b6', tickMarkerStroke : 1 }; var median = { tickMarkerSize : 4, tickMarkerColor : '#d35400', tickMarkerStroke : 1.2, tickTextColor : '#d35400', tickTextFontSize : 10 }; var major = { tickMarkerSize : 8, tickMarkerColor : '#2980b9', tickMarkerStroke : 3, tickTextColor : '#2980b9', tickTextFontSize : 12, tickTextOffset : 16 }; function createViewStockMACD(container1,container2, width, height) { //view var view = new JenScript.View({ name : container1, width : width, height : height, east : 10, west : 80, south : 80, }); var startDate = ne
Find elsewhere
🌐
Syncfusion
ej2.syncfusion.com › demos › chart › moving-average-convergence-divergence-indicator
Javascript Chart MACD Example - Syncfusion Demos
Tooltip is enabled in this example, to see the tooltip in action, hover a point or tap on a point in touch enabled devices. Injecting Module Chart component features are segregated into individual feature-wise modules. To use MACD Indicator, we need to Inject MacdIndicator module using chart.Inj...
🌐
Aryalinux
aryalinux.org › home › programming › compute moving average convergence divergence (macd) in javascript?
Compute Moving Average Convergence Divergence (MACD) In JavaScript in 2024?
October 9, 2024 - In JavaScript, you can compute the MACD by first calculating the 12-day and 26-day EMA of the price data using a recursive formula, and then subtracting the two EMAs to get the MACD line.
🌐
npm
npmjs.com › package › technicalindicators
technicalindicators - npm
March 16, 2020 - This a merge of calculate and nextValue. The usual use case would be ... Use nextValue to get next indicator values for further tick. var sma = new SMA({period : period, values : prices}); ... Note: Calling nextValue will not update getResult() value. This uses regular javascript numbers, so there can be rounding errors which are negligible for a technical indicators, you can set precision by using the below config.
      » npm install technicalindicators
    
Published   Mar 16, 2020
Version   3.1.0
🌐
GitHub
github.com › anandanand84 › technicalindicators
GitHub - anandanand84/technicalindicators: A javascript technical indicators written in typescript with pattern recognition right in the browser · GitHub
This a merge of calculate and nextValue. The usual use case would be ... Use nextValue to get next indicator values for further tick. var sma = new SMA({period : period, values : prices}); sma.getResult(); // [5.5, 6.6, 7.7, 8.9] sma.nextValue(16); // 10.1 · Note: Calling nextValue will not update getResult() value. This uses regular javascript numbers, so there can be rounding errors which are negligible for a technical indicators, you can set precision by using the below config.
Starred by 2.4K users
Forked by 581 users
Languages   JavaScript 65.0% | TypeScript 33.6% | HTML 1.3%
🌐
GitHub
gist.github.com › bepitulaz › 5fc2b4a2a42b5225e2ea47b098a12883
Calculate simple moving average in JavaScript. · GitHub
Calculate simple moving average in JavaScript. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › topics › macd
macd · GitHub Topics · GitHub
A Moving Average Convergence / Divergence calculation algorithm. ... An example project to display Stock / Crypto candle chart ( Plotly ) with Angular 8. The chart gets it's data from Poloniex · plotlyjs cci poloniex macd technicalindicators angular-plotlyjs candle-chart ... A versatile, compact (807-byte) implementation of Gerald Appel's MACD (Moving Average Convergence / Divergence) formula. javascript ...
🌐
npms
npms.io › search
macd
npms was built to empower the javascript community by providing a better and open sourced search for node modules.
🌐
Syncfusion
ej2.syncfusion.com › javascript › demos › chart › moving-average-convergence-divergence-indicator
Javascript (ES5) Chart MACD Example - Syncfusion Demos
The moving average is based on the difference between two EMA's. This indicator often provides valuable signals for trend analysis. Tooltip is enabled in this example, to see the tooltip in action, hover a point or tap on a point in touch enabled devices. More information on the MACD Indicator can be found in this documentation section.
🌐
Npm
npm.io › search › keyword:macd
Macd | npm.io
A pure js library to calculate MACD/KDJ/BOLL... for stock ... ui5openui5d3stockexchangecandlecandlestickfinancialchartindicator1.0.5-beta • Published 6 years ago ... Technical indicatorsTechnical analysisfinanceforexstocksBitcoinEthereumCrypto Currencyrsirelative strength index2.0.3 • Published 8 years ago · A versatile 807-byte Javascript implementation of the MACD formula.