From dc8e3402944548dbe668a89b686f4da56612d84b Mon Sep 17 00:00:00 2001 From: moshferatu Date: Fri, 8 Nov 2024 10:52:52 -0800 Subject: [PATCH] Add script for generating Turnaround Tuesday (or Monday) swing trading signals --- strategies/turnaround.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 strategies/turnaround.py diff --git a/strategies/turnaround.py b/strategies/turnaround.py new file mode 100644 index 0000000..5e18f75 --- /dev/null +++ b/strategies/turnaround.py @@ -0,0 +1,16 @@ +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 \ No newline at end of file