Created
May 6, 2023 07:16
-
-
Save under0tech/493161ec6dcb6c35b3a52d26fdf6cd73 to your computer and use it in GitHub Desktop.
This file contains 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
# SCREENER | |
def screen_stock(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) | |
bbands2 = ta.bbands(df['Close'], length = 20, std=2.2) | |
bbands3 = ta.bbands(df['Close'], length = 20, std=2.3) | |
df['L2'] = bbands2['BBL_20_2.2'] | |
df['M2'] = bbands2['BBM_20_2.2'] | |
df['U2'] = bbands2['BBU_20_2.2'] | |
df['L3'] = bbands3['BBL_20_2.3'] | |
df['M3'] = bbands3['BBM_20_2.3'] | |
df['U3'] = bbands3['BBU_20_2.3'] | |
previous_bar = df[-2:].head(1) | |
current_bar = df[-1:] | |
if current_bar['U2'].values[0] < current_bar['Close'].values[0] and \ | |
current_bar['U3'].values[0] > current_bar['Close'].values[0] and \ | |
current_bar['rsi'].values[0] > 70: | |
data = { 'direction': 'DOWN', 'stock' : stock, 'stop_loss': round(max(previous_bar['Close'].values[0], current_bar['U3'].values[0]) * (1 + STOP_LOSS_DELTA), 2), \ | |
'take_profit': round(max(current_bar['Close'].values[0] * (1 - TAKE_PROFIT_DELTA), current_bar['M2'].values[0]) , 2) } | |
elif current_bar['L2'].values[0] > current_bar['Close'].values[0] and \ | |
current_bar['L3'].values[0] < current_bar['Close'].values[0] and \ | |
current_bar['rsi'].values[0] < 30: | |
data = { 'direction': 'UP', 'stock' : stock, 'stop_loss': round(min(previous_bar['L3'].values[0], current_bar['L3'].values[0]) * (1 - STOP_LOSS_DELTA), 2), \ | |
'take_profit': round(min(current_bar['Close'].values[0] * (1 + TAKE_PROFIT_DELTA), current_bar['M2'].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