17 lines
666 B
Python
17 lines
666 B
Python
from pandas import DataFrame, Series
|
|
|
|
def signals(data: DataFrame) -> Series:
|
|
"""
|
|
Generate swing trading signals based on the High Volume Days strategy.
|
|
|
|
Returns a Series with 'L' for long signals and 'N' otherwise.
|
|
"""
|
|
data['200_MA'] = data['Close'].rolling(window = 200).mean()
|
|
above_200_ma = data['Close'] > data['200_MA']
|
|
|
|
highest_volume = data['Volume'] == data['Volume'].rolling(window = 5).max()
|
|
close_lower_than_open = data['Close'] < data['Open']
|
|
|
|
signal_condition = above_200_ma & highest_volume & close_lower_than_open
|
|
signals = signal_condition.apply(lambda condition: 'L' if condition else 'N')
|
|
return signals |