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

Argument of type '{ period: any; prices: any; }' is not assignable to parameter of type 'MAInput' #198

Open rezaee opened 4 years ago

rezaee commented 4 years ago

I want to use technicalindicators in my Angular app written in TypeScript, but don't know how to import and use it?

What I want to do is calculating SMA(Simple Moving Averages) of an array.

EDIT:

I have installed technicalindicators module using npm i --save technicalindicators command. Then I imported it like this:

import {sma} from 'technicalindicators';

Then I tried to use it like this:

var prices = [1,2,3,4,5,6,7,8,9,10,12,13,15];
var period = 10;

  doSMA(period , prices){
    console.log('sma result is:' , sma({period, prices}));
  }

But I get this error message:

Argument of type '{ period: any; prices: any; }' is not assignable to parameter of type 'MAInput'

hmG3 commented 4 years ago

The class MAInput defined as:

class MAInput {
    period: number;
    values: number[];
}

You either need to change the prices variable name to "values" or explicitly pass the price array to "values" property:

doSMA(period, prices) {
    console.log('sma result is:' , sma({period, values: prices}));
}
rezaee commented 4 years ago

The class MAInput defined as:

class MAInput {
    period: number;
    values: number[];
}

You either need to change the prices variable name to "values" or explicitly pass the price array to "values" property:

doSMA(period, prices) {
    console.log('sma result is:' , sma({period, values: prices}));
}

Thank you very much!