From 8a89fa621bdbb9b6aaad20c6878a364116029db4 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 19 Dec 2024 13:35:14 -0800 Subject: [PATCH] Initial commit of Engulfing swing trading strategy --- strategies/engulfing.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 strategies/engulfing.py diff --git a/strategies/engulfing.py b/strategies/engulfing.py new file mode 100644 index 0000000..2b0e2f4 --- /dev/null +++ b/strategies/engulfing.py @@ -0,0 +1,16 @@ +from numpy import where +from pandas import DataFrame, Series + +from indicators import sma + +def engulfing(data: DataFrame) -> Series: + """ + Generate swing trading signals based on the engulfing candlestick pattern. + + Returns a Series with 'L' for long signals and 'N' otherwise. + """ + is_engulfing = (data['High'] > data['High'].shift(1)) & (data['Close'] < data['Low'].shift(1)) + is_above_200_ma = data['Close'] > sma(data, period = 200) + + conditions = is_engulfing & is_above_200_ma + return Series(where(conditions, 'L', 'N'), index = data.index) \ No newline at end of file