From 78be11ee9deee9b72606b9fe544d65b0cc3f3fc2 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Sun, 17 Nov 2024 00:47:41 -0800 Subject: [PATCH] Add script for generating Internal Bar Strength Band strategy signals --- strategies/internal_bar_strength_band.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 strategies/internal_bar_strength_band.py 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