swing-trading-dashboard/strategies/down_days_in_a_row.py

12 lines
439 B
Python

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