Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs talib MACD

I am using talib technical analysis library to calculate MACD.
I used AAPL data to calculate MACD(8, 17, 9) but the talib values are completely different from Google and Yahoo finance.
Here is my javascript (I copied last AAPL close data since 2015-08-21):

var talib = require('./node_modules/talib/build/Release/talib');
var marketData = { open: [], close: [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],high: [], low: [], volume: [] };
 talib.execute({
    name: "MACD",
    startIdx: 0,
    endIdx: marketData.close.length - 1,
    inReal: marketData.close,
    optInFastPeriod: 8,
    optInSlowPeriod: 17,
    optInSignalPeriod: 9
}, function (result) {
   console.log(result);
});

MACD value of 2005-08-21 from Yahoo and Google finance is -2.73, talib value is 3.83 and with more data MACD are very different. What I am doing wrong?
I also noticed that talib SMA and EMA give the same results.
By the way, inverting in Google charts MACD slow and fast periods, does not change the chart... Yahoo does.

like image 487
Stefano Piovesan Avatar asked Aug 24 '26 19:08

Stefano Piovesan


1 Answers

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 ] ]
like image 155
acrazing Avatar answered Aug 26 '26 09:08

acrazing