Last active
January 12, 2021 18:23
-
-
Save lvthillo/9964a34dac60c35582924335acd67cb7 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
signal = stock_data['macds'] # Your signal line | |
macd = stock_data['macd'] # The MACD that need to cross the signal line | |
advice = ["No data"] # Since you need at least two hours in the for loop | |
for i in range(1, len(signal)): | |
# If the MACD crosses the signal line upward | |
if macd[i] > signal[i] and macd[i - 1] <= signal[i - 1]: | |
advice.append("BUY") | |
# The other way around | |
elif macd[i] < signal[i] and macd[i - 1] >= signal[i - 1]: | |
advice.append("SELL") | |
# Do nothing if not crossed | |
else: | |
advice.append("HOLD") | |
stock_data['advice'] = advice | |
print(stock_data['advice']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment