Diversion

17
def high_accuracy_signal(df):
df['ma10'] = df['close'].rolling(10).mean()
df['ma50'] = df['close'].rolling(50).mean()
df['rsi'] = compute_rsi(df['close'], 14)
df['avg_volume'] = df['volume'].rolling(5).mean()

df['signal'] = (
(df['close'] > df['ma50']) &
(df['rsi'] > 55) & (df['rsi'] < 70) &
(df['volume'] > 2 * df['avg_volume'])
)

return df[['close', 'rsi', 'volume', 'signal']]

def compute_rsi(series, period=14):
delta = series.diff()
gain = delta.where(delta > 0, 0)
loss = -delta.where(delta < 0, 0)
avg_gain = gain.rolling(period).mean()
avg_loss = loss.rolling(period).mean()
rs = avg_gain / avg_loss
rsi = 100 - (100 / (1 + rs))
return rsi

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.