From 89029dd7a582f0592f93bd38f37efdfabb9c2d82 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 31 Oct 2024 09:37:49 -0700 Subject: [PATCH] Add script for generating down days in a row trading signals --- strategies/down_days_in_a_row.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 strategies/down_days_in_a_row.py diff --git a/strategies/down_days_in_a_row.py b/strategies/down_days_in_a_row.py new file mode 100644 index 0000000..566c705 --- /dev/null +++ b/strategies/down_days_in_a_row.py @@ -0,0 +1,11 @@ +from pandas import DataFrame, Series + +def signals(data: DataFrame) -> Series: + """ + Generate signals for entering a long trade when the market's + close price is lower for 3 consecutive days. + + Returns a Series with 'L' for long signals and 'N' otherwise. + """ + lower_close = data['Close'] < data['Close'].shift(1) + return (lower_close & lower_close.shift(1) & lower_close.shift(2)).apply(lambda x: 'L' if x else 'N')