Skip to content

Instantly share code, notes, and snippets.

@lvthillo
Last active January 12, 2021 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvthillo/9964a34dac60c35582924335acd67cb7 to your computer and use it in GitHub Desktop.
Save lvthillo/9964a34dac60c35582924335acd67cb7 to your computer and use it in GitHub Desktop.
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