Open josuhap opened 2 years ago
You may better read the discussion about indicators with "memory effect" here: https://github.com/mrjbq7/ta-lib/issues/469
Hello @trufanov-nok,
First of all thank you for your response, I have read that discussion but I think the problem is not the same.
To avoid "memory effect" about indicators, I use this commands:
closes = 0 np_closes = 0 erre = 0 rsis = 0 datas = 0
So I am assuming that with those commands I "reset" all the values of them.
In none of the cases the RSI is the correct (1m -> 1/2/3 hours ago and 5m -> 1/2/3 hours ago).
PD: I understand the "memory effect" but only I need is the last value rsis[-1], and that's a worng value
I think you misunderstand "memory effect", it's not the memory used by Python objects, but rather the influence on your latest RSI value by all previous observed values.
I reproduced this code and assume the problem is in the difference between data returned to python via binance API and data displayed on graph online. I mean their klines' closes are different. Sometimes significantly. Could you confirm?
For the reference my test server code is:
from datetime import datetime
import numpy as np
import talib
from binance.client import Client
client = Client("ALUdiXPFeGbBRa533X8msQJNxp75st0F7W98uInhAg6pGFXD5OXcuDiLwkgjbRxy", "gl5Mcg9CnLOEzYWwN0z2hFgWSySsf3sI8AxzIOsDbItyvcGrk9cASmGxfDrwK3BF", testnet=True)
symbol = 'BTCUSDT'
periods = [Client.KLINE_INTERVAL_5MINUTE, Client.KLINE_INTERVAL_1MINUTE]
diff = ['1','2','3', '10']
closes = []
for period in periods:
print(f'{symbol} - {period}')
for hour in diff:
ago = f'{hour} hours ago'
datas = client.get_historical_klines(symbol,period, ago)
for data in datas[:-1]:
timestamp = datetime.utcfromtimestamp(int(data[0]/1000)).strftime('%Y-%m-%d %H:%M:%S')
price = round(float(data[4]),2)
closes.append(price)
np_closes = np.array(closes)
erre = talib.RSI(np_closes, 14)
rsis = erre.tolist()
print(f'{timestamp} -> {symbol} -> {rsis[-1]} - {ago}')
you must have a big data because stock calculate rsi from the first date but you use a specefic date, and this diffrent is effective on your calculate but if your date was long the diffrent is small sorry for my weak english:)
I'm developing a small python script to get the RSI of a stock using TA-Lib. It was working fine for 6 months but now I realized the RSI function from TA-Lib is returning worng values:
Here an screenshot trying to get RSI from different timeframes (1m and 5m) with the difference of the candle numbers.
I have a big question... If RSI function only gets last 14 values, why the value is so different between those tfs?
Correct value at 5m tf
Correct value at 1m tf
Version: