debut-js / Indicators

Technical indicators for cryptocurrencies, stocks and forex. To work with historical and real price data. One of the most efficient Javascript library implementations. The library has such indicators as: Relative Strength Index (RSI), Moving Average C / D (MACD), Average Directional Index (ADX), Stochastic Oscillator, Bollinger Bands, Average True Range (ATR) and many others

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MACD

emorling opened this issue · comments

Some of the indicators simply return undefined values. See this simple example, why are all the values undefined?

const { MACD } = require('@debut/indicators');

const values = [127.75, 129.02, 132.75, 145.40, 148.98, 137.52, 147.38, 139.05, 137.23, 149.30, 162.45, 178.95, 200.35, 221.90, 243.23, 243.52, 286.42, 280.27, 277.35, 269.02, 263.23, 214.90];

const macd = new MACD();
values.forEach((value) => {
  const nextValue = macd.nextValue(value);
  console.log(nextValue);
});

Your example array has a length of 22. The default parameters for the MACD is

    constructor(private periodEmaFast = 12, private periodEmaSlow = 26, private periodSi)

All the indicators will return undefined until you fill the minimum buffer required to generate a result.

Make sure you have enough data in your test array to generate a response.