diff --git a/strategies/double_5s.py b/strategies/double_5s.py new file mode 100644 index 0000000..cbaeaec --- /dev/null +++ b/strategies/double_5s.py @@ -0,0 +1,22 @@ +import pandas as pd + +def signals(data: pd.DataFrame) -> pd.Series: + """ + Generate trading signals based on the following rules: + 1. SPY is above its 200-day moving average. + 2. Enter a long position if SPY closes at a 5-day low. + + This strategy is based on the Double 7's strategy by Larry Connors. + + Returns a Series with 'L' for long signals and 'N' for no signal. + """ + ma_200 = data['Close'].rolling(window = 200).mean() + low_5_day = data['Close'].rolling(window = 5).min() + + above_200_ma = data['Close'] > ma_200 + at_5_day_low = data['Close'] == low_5_day + + signals = pd.Series('N', index = data.index) + signals[above_200_ma & at_5_day_low] = 'L' + + return signals \ No newline at end of file