anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.14k stars 557 forks source link

Help: Can't get Heikin Ashi to work #202

Closed maximusign closed 4 years ago

maximusign commented 4 years ago

Hi there,

I'm trying to implement the Heikin Ashi chart type, but getting an "Cannot read property 'forEach' of undefined" error. I'm sure it's something I'm doing, and would appreciate any help!

// Load library
var HeikinAshi = require('technicalindicators').HeikinAshi;

// Create some data
var HAInput = {
    open: [23.25,15.36],
    high: [25.10,30.87],
    close: [21.44,27.89],
    low: [20.82,14.93],
  }

  // Run package and output
  HA = new HeikinAshi({period : 2, values : HAInput})
  console.log(HeikinAshi(HA)); 

Is giving me this error.

$ node test.js /Users/ep/Documents/ft/Node/Vertical/node_modules/technicalindicators/dist/index.js:2616 input.low.forEach((tick, index) => { ^

TypeError: Cannot read property 'forEach' of undefined at new HeikinAshi (/Users/ep/Documents/ft/Node/Vertical/node_modules/technicalindicators/dist/index.js:2616:19)

jaggedsoft commented 4 years ago

have you tried this?

HA = new HeikinAshi({period : 2, open: HAInput.open, high: HAInput.high, low: HAInput.low, close: HAInput.close});

I think it takes open, high, low, close values by themselves instead of in a values object

maximusign commented 4 years ago

That worked! Thanks for the help @jaggedsoft!