python-tradingview-ta
python-tradingview-ta copied to clipboard
RSI parameters (Time Frame)
I use TradingView, but I have been calculating 10 day RSI (which is the standard) using YahooFinance.
I find that my RSI calculations differ from TradingView, so I have decided to get the data from TradingView via your API.
from tradingview_ta import TA_Handler, Interval, Exchange
tesla = TA_Handler(
symbol="TSLA",
screener="america",
exchange="NASDAQ",
interval=Interval.INTERVAL_1_DAY,
# proxies={'http': 'http://example.com:8080'} # Uncomment to enable proxy (replace the URL).
)
print(tesla.get_analysis().indicators["RSI"])
this returns 66.32.
When I go to TradingView, with RSI set to Timeframe 1 DAY and RSI Time Frame to 10,
the resultant RSI is 73.92
using my Gorilla Yahoo RSI method, the RSI is 82.
import pandas_ta as ta
import datetime
import time
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay
US_BUSINESS_DAY = CustomBusinessDay(calendar=USFederalHolidayCalendar())
from yahoo_fin import stock_info as si
def load_historic_data(symbol):
today = datetime.date.today()
today_str = today.strftime("%Y-%m-%d")
# Get last 11 days of data
start_date = today - (11 * US_BUSINESS_DAY)
start_date_str = datetime.datetime.strftime(start_date, "%Y-%m-%d")
try:
# Download data from Yahoo Finance
df = si.get_data(symbol, start_date=start_date_str, end_date=today_str, index_as_date=False)
return df
except:
print('Error loading stock data for ' + symbol)
return None
def calculate_technical_indicators(df):
df['RSI'] = ta.rsi(df["adjclose"], length=10)
return df
def backtest_RSI(symbol):
my_df = load_historic_data(symbol)
try:
calc_df = calculate_technical_indicators(my_df)
print(calc_df)
return calc_df.iat[10,8] #this is our RSI
except:
print("had problems with ", symbol)
return
testee = 'TSLA'
print(backtest_RSI(testee))
Is there a way to adjust the RSI parameter?
actually, I found my issue. If I extend the data on my Gorilla Yahoo RSI data to 60 days, then the RSI numbers are within .01 of the correct value.