From d887e6e7b38a3525d4a1a7397e4bf8dbc7170e0c Mon Sep 17 00:00:00 2001 From: moshferatu Date: Sun, 27 Oct 2024 06:38:20 -0700 Subject: [PATCH] Add script for calculating internal bar strength signals --- strategies/internal_bar_strength.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 strategies/internal_bar_strength.py diff --git a/strategies/internal_bar_strength.py b/strategies/internal_bar_strength.py new file mode 100644 index 0000000..4cfa0c9 --- /dev/null +++ b/strategies/internal_bar_strength.py @@ -0,0 +1,9 @@ +from pandas import DataFrame, Series + +def signals(data: DataFrame) -> Series: + """ + Calculate the Internal Bar Strength (IBS) signal. + Returns a Series with 'L' for long signals and 'N' otherwise. + """ + ibs_series = (data['Close'] - data['Low']) / (data['High'] - data['Low']) + return ibs_series.apply(lambda ibs: 'L' if ibs < 0.2 else 'N')