technicalindicators icon indicating copy to clipboard operation
technicalindicators copied to clipboard

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

Open rezaee opened this issue 5 years ago • 2 comments

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'

rezaee avatar Jan 16 '20 19:01 rezaee

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}));
}

hmG3 avatar Jan 16 '20 20:01 hmG3

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!

rezaee avatar Jan 17 '20 06:01 rezaee