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 OverflowMaybe 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 ] ]
25 data points is not enough to get a good result. Calculation of an EMA series (MACD is based on multiple sets of EMA series) is recursive. for calculating EMA/MACD, i'd say use at least a year's worth of closing price data.
smoke-screen testing of technical indicator software can be rather arduous since you have to be certain you're using the exact same set of data, ensure you're starting with the same initial priming values, etc., as the reference system/calculation is.
as far as getting the data, yahoo is one option obviously. markit also offers an api that might work which returns historical prices.
» npm install macd
» npm install technicalindicators