Add script for generating High Volume Days strategy signals

This commit is contained in:
moshferatu 2024-11-17 00:48:02 -08:00
parent 78be11ee9d
commit 5ba183d06e

View File

@ -0,0 +1,17 @@
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['Total Volume'] == data['Total 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