swing-trading-dashboard/strategies/turnaround.py

16 lines
631 B
Python

from pandas import DataFrame, Series, to_datetime
def signals(data: DataFrame) -> Series:
"""
Generate long signals based on the day of the week and downward close conditions.
Returns a Series with 'L' for long signals and 'N' for no signal.
"""
date_series = to_datetime(data['Date'], errors = 'coerce')
monday_or_tuesday = date_series.dt.dayofweek.isin([0, 1])
lower_past_two_days = (data['Close'] < data['Close'].shift(1)) & (data['Close'].shift(1) < data['Close'].shift(2))
signals = Series('N', index=data.index)
signals[monday_or_tuesday & lower_past_two_days] = 'L'
return signals