Created
September 26, 2022 17:39
-
-
Save under0tech/e04661b52f90a752cd7261f1e9394a7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check stock with TA indicators | |
def CheckStock(stock): | |
data = {} | |
try: | |
df = yf.download(stock, period = SCREENER_PERIOD, interval = SCREENER_INTERVAL) | |
if (len(df) > 0): | |
df['RSI'] = ta.rsi(df['Close'], timeperiod=14) | |
bbands = ta.bbands(df['Close'], length = 20, std=2.3) | |
df['L'] = bbands['BBL_20_2.3'] | |
df['M'] = bbands['BBM_20_2.3'] | |
df['U'] = bbands['BBU_20_2.3'] | |
previous2_bar = df[-3:].head(1) | |
previous_bar = df[-2:].head(1) | |
current_bar = df[-1:] | |
if current_bar['RSI'].values[0] > 70 and \ | |
current_bar['Close'].values[0] > current_bar['U'].values[0]: | |
data = { 'direction': 'DOWN', 'stock' : stock, 'stop_loss': round(max(previous_bar['High'].values[0], previous2_bar['High'].values[0], previous_bar['U'].values[0]), 2), \ | |
'take_profit': round(min(previous_bar['Low'].values[0], previous2_bar['Low'].values[0], previous_bar['M'].values[0]), 2) } | |
elif current_bar['RSI'].values[0] < 30 and \ | |
current_bar['Close'].values[0] < current_bar['L'].values[0]: | |
data = { 'direction': 'UP', 'stock' : stock, 'stop_loss': round(min(previous_bar['Low'].values[0], previous2_bar['Low'].values[0], previous_bar['L'].values[0]), 2), \ | |
'take_profit': round(max(previous_bar['High'].values[0], previous2_bar['High'].values[0], previous_bar['M'].values[0]), 2) } | |
except: | |
pass | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment