Initial commit of Engulfing swing trading strategy
This commit is contained in:
parent
e22e5128a7
commit
8a89fa621b
16
strategies/engulfing.py
Normal file
16
strategies/engulfing.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user