anandanand84 / technicalindicators

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

[TIP] for people getting wrong values #257

Open marcusmota opened 2 years ago

marcusmota commented 2 years ago

Hi guys I noticed a lot of people are complaining about having wrong values.

my RSI has the correct values, keep in mind the indicator values and the candle close values have different array lengths

let's say you have

const arrClose = [1,2,3,4,5];
const rsi = [...someValues];

keep in mind rsi.length !== arrClose.length so if you add a loop to iterate through arrClose and use the index to access the rsi[i] you will get the wrong value for your RSI, you need to kind of adjust your "i" to access the correct value, something like

const diff = arrClose.length - rsi.length; //usually is 14 but you need to check on the code
for (let i=0;i<arrClose.length;i++) {
   const rsiValue = rsi[i-diff] //rather than rsi[i];
   //do whatever you need
}

Good luck!