Last active
January 8, 2021 04:16
-
-
Save s-tlm/eaaf916d56c01fc2f6f41fdd072019aa to your computer and use it in GitHub Desktop.
Buy/Sell signal generator
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
| buy = pd.DataFrame(index=closing_prices.index, columns=['Buy']) # an empty data-frame to store buy signals | |
| sell = pd.DataFrame(index=closing_prices.index, columns=['Sell']) # an empty data-frame to store sell signals | |
| for i in range(1, len(closing_prices)): # ignores first value of historical data as MACD will be equal to signal line there | |
| if i == 1: | |
| if MACD['EMA'].iloc[i] > signal_line['EMA'].iloc[i]: | |
| high = 'MACD' | |
| else: | |
| high = 'SIGNAL' | |
| elif MACD['EMA'].iloc[i] > signal_line['EMA'].iloc[i]: | |
| if high == 'SIGNAL': # MACD crossed signal - bottom to top BUY | |
| if MACD['EMA'].iloc[i] < 0: | |
| buy.iloc[i] = closing_prices[i] # BUY | |
| high = 'MACD' | |
| elif MACD['EMA'].iloc[i] < signal_line['EMA'].iloc[i]: | |
| if high == 'MACD': # MACD crossed signal - top to bottom SELL | |
| if MACD['EMA'].iloc[i] > 0: | |
| sell.iloc[i] = closing_prices[i] # SELL | |
| high = 'SIGNAL' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment