import pandas as pd
import numpy as np
import talib
data = pd.DataFrame({
'close': [100, 105, 110, 115, 120, 115, 110, 105, 100, 95],
'high': [105, 110, 115, 120, 125, 120, 115, 110, 105, 100],
'low': [95, 100, 105, 110, 115, 110, 105, 100, 95, 90]
})
rsi_period = 14
macd_fast_period = 12
macd_slow_period = 26
macd_signal_period = 9
rsi = talib.RSI(data['close'], timeperiod=rsi_period)
macd, signal, _ = talib.MACD(data['close'], fastperiod=macd_fast_period, slowperiod=macd_slow_period, signalperiod=macd_signal_period)
def combine_signals(rsi, macd):
signals = []
for i in range(len(rsi)):
if rsi > 70 and macd > 0:
signals.append('Sell')
elif rsi < 30 and macd < 0:
signals.append('Buy')
else:
signals.append('Hold')
return signals
combined_signals = combine_signals(rsi, macd)
data['RSI'] = rsi
data['MACD'] = macd
data['Combined_Signal'] = combined_signals
print(data)
import numpy as np
import talib
data = pd.DataFrame({
'close': [100, 105, 110, 115, 120, 115, 110, 105, 100, 95],
'high': [105, 110, 115, 120, 125, 120, 115, 110, 105, 100],
'low': [95, 100, 105, 110, 115, 110, 105, 100, 95, 90]
})
rsi_period = 14
macd_fast_period = 12
macd_slow_period = 26
macd_signal_period = 9
rsi = talib.RSI(data['close'], timeperiod=rsi_period)
macd, signal, _ = talib.MACD(data['close'], fastperiod=macd_fast_period, slowperiod=macd_slow_period, signalperiod=macd_signal_period)
def combine_signals(rsi, macd):
signals = []
for i in range(len(rsi)):
if rsi > 70 and macd > 0:
signals.append('Sell')
elif rsi < 30 and macd < 0:
signals.append('Buy')
else:
signals.append('Hold')
return signals
combined_signals = combine_signals(rsi, macd)
data['RSI'] = rsi
data['MACD'] = macd
data['Combined_Signal'] = combined_signals
print(data)
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.