I'm using talib-binding for node in my project to calculate RSI based on Binance's websocket candlestick feed.
I would like to sync my RSI output as much as I can with what Binance's RSI indicator shows, but interestingly for the default 14 period I get different RSI output for different sized input arrays. For example:
//Chart interval 1 min in both cases
console.log(`records length: ${this.records.length}`); // length: 14
const outReal = talib.RSI(this.records, 'Close');
console.log(outReal) // ouputs: 56
------
console.log(`records length: ${this.records.length}`); // length: 70
const outReal = talib.RSI(this.records, 'Close');
console.log(outReal) // ouputs: 21
I'm confused, with the period set to 14 (default) shouldn't RSI take in account only the last 14 candles (chart interval 1 min)?
As for synching my output with Binance's RSI. The only way I could synch the two was by truncating the input array to exactly 14 items, now the two outputs are really close but not consistent.
Thanks!
RSI is an indicator based on a moving window. Timeperiod is a size of this window. RSI on a next day depends on RSI value of a previous day. If your data length is 14 talib supposed to return an array of size 1 or array of size 14 with 13 NaNs and 1 meaningful value (depends on implementation of your binding). If your data length is 70, talib is supposed to return array with at least 56 RSI values for last 56 days. Probably node binding returns only last day value which would be weird or you do something wrong - return values must be arrays.
Would RSI calculated for a last 14 days be equal to the last RSI of 70 days data? No. Bcs RSI of a next day depends on RSI of the previous day it's aware not only 14-days but also data earlier. It affects RSI value with a certain weights which are decreasing to 0 (exponential smoothing). So, to sync your RSI with Binance's RSI you better to find out when they started their RSI calculation - it might be a beginning of the year or even beginning of historical data. And if you can't start RSI calculation from their starting point to exactly reproduce their results then you may take big enough data in a hope that although RSI will differ with Binance's RSI in a beginning of this data its value will converge to Binance's RSI value for days at the end of this data as influence of old data is decreasing for new RSIs.