Add script for generating down days in a row trading signals

This commit is contained in:
moshferatu 2024-10-31 09:37:49 -07:00
parent e8eceb2c59
commit 89029dd7a5

View File

@ -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')