From 9aebe2f13585a268f3ee064b597edc276a68428e Mon Sep 17 00:00:00 2001 From: moshferatu Date: Wed, 8 Jan 2025 10:50:43 -0800 Subject: [PATCH] Initial commit of ConnorsRSI strategy --- strategies/connors_rsi.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 strategies/connors_rsi.py diff --git a/strategies/connors_rsi.py b/strategies/connors_rsi.py new file mode 100644 index 0000000..7629677 --- /dev/null +++ b/strategies/connors_rsi.py @@ -0,0 +1,19 @@ +from numpy import where +from pandas import DataFrame, Series + +from indicators import sma, connors_rsi as crsi + +def connors_rsi(data: DataFrame) -> Series: + """ + Calculate signals for the ConnorsRSI strategy. + + Returns a Series with 'L' for long signals and 'N' otherwise. + """ + ma_200 = sma(data, period = 200) + connors_rsi_values = crsi(data) + + above_ma_200 = data['Close'] > ma_200 + connors_rsi_below_15 = connors_rsi_values < 15 + + conditions = above_ma_200 & connors_rsi_below_15 + return Series(where(conditions, 'L', 'N'), index = data.index) \ No newline at end of file