diff --git a/strategies/internal_bar_strength_band.py b/strategies/internal_bar_strength_band.py new file mode 100644 index 0000000..e946d6b --- /dev/null +++ b/strategies/internal_bar_strength_band.py @@ -0,0 +1,22 @@ +import pandas as pd + +def signals(data: pd.DataFrame) -> pd.Series: + """ + Calculate swing trading signals based on Internal Bar Strength Band strategy. + + Returns a Series with 'L' for long signals and 'N' otherwise. + """ + ma_200 = data['Close'].rolling(window = 200).mean() + + rolling_high_minus_low = (data['High'] - data['Low']).rolling(window = 25).mean() + rolling_high = data['High'].rolling(window = 10).max() + lower_band = rolling_high - 2.5 * rolling_high_minus_low + + ibs = (data['Close'] - data['Low']) / (data['High'] - data['Low']) + + signals = ( + (data['Close'] > ma_200) & + (data['Close'] < lower_band) & + (ibs < 0.3) + ).apply(lambda condition: 'L' if condition else 'N') + return signals \ No newline at end of file