Fixed signal logic bugs: changed if to elif for mutually exclusive signals, added RSI_SELL_MIN condition, fixed crossover boundary checks
This commit is contained in:
1 parent
efdbcd0899
commit
0a943754a3
1 file changed
+4
-2
@@ -441,6 +441,7 @@ def advanced_signal_generator(symbol):
|
|||||||
|
|
||||||
for i in range(1, CROSSOVER_LOOKBACK + 1):
|
for i in range(1, CROSSOVER_LOOKBACK + 1):
|
||||||
bar_index = current_bar_index - i
|
bar_index = current_bar_index - i
|
||||||
|
if bar_index >= 1 and (i + 1) < len(short_ma_series):
|
||||||
if short_ma_series.iloc[-i-1] <= long_ma_series.iloc[-i-1] and short_ma_series.iloc[-i] > long_ma_series.iloc[-i]:
|
if short_ma_series.iloc[-i-1] <= long_ma_series.iloc[-i-1] and short_ma_series.iloc[-i] > long_ma_series.iloc[-i]:
|
||||||
if bar_index > signal_state.last_bullish_crossover_bar:
|
if bar_index > signal_state.last_bullish_crossover_bar:
|
||||||
bullish_crossover = True
|
bullish_crossover = True
|
||||||
@@ -450,6 +451,7 @@ def advanced_signal_generator(symbol):
|
|||||||
|
|
||||||
for i in range(1, CROSSOVER_LOOKBACK + 1):
|
for i in range(1, CROSSOVER_LOOKBACK + 1):
|
||||||
bar_index = current_bar_index - i
|
bar_index = current_bar_index - i
|
||||||
|
if bar_index >= 1 and (i + 1) < len(short_ma_series):
|
||||||
if short_ma_series.iloc[-i-1] >= long_ma_series.iloc[-i-1] and short_ma_series.iloc[-i] < long_ma_series.iloc[-i]:
|
if short_ma_series.iloc[-i-1] >= long_ma_series.iloc[-i-1] and short_ma_series.iloc[-i] < long_ma_series.iloc[-i]:
|
||||||
if bar_index > signal_state.last_bearish_crossover_bar:
|
if bar_index > signal_state.last_bearish_crossover_bar:
|
||||||
bearish_crossover = True
|
bearish_crossover = True
|
||||||
@@ -500,7 +502,7 @@ def advanced_signal_generator(symbol):
|
|||||||
position_type = "long"
|
position_type = "long"
|
||||||
debug_print(f"BUY signal: strength={strength:.2f}, stop=${stop:.2f}")
|
debug_print(f"BUY signal: strength={strength:.2f}, stop=${stop:.2f}")
|
||||||
|
|
||||||
if short_ma < long_ma and rsi_val < RSI_SELL_MAX:
|
elif short_ma < long_ma and rsi_val > RSI_SELL_MIN and rsi_val < RSI_SELL_MAX:
|
||||||
if REQUIRE_MA_CROSSOVER and not bearish_crossover:
|
if REQUIRE_MA_CROSSOVER and not bearish_crossover:
|
||||||
debug_print("Bearish signal rejected: no recent crossover")
|
debug_print("Bearish signal rejected: no recent crossover")
|
||||||
elif REQUIRE_CANDLE_PATTERN and not bearish_pattern:
|
elif REQUIRE_CANDLE_PATTERN and not bearish_pattern:
|
||||||
@@ -525,7 +527,7 @@ def advanced_signal_generator(symbol):
|
|||||||
position_type = "long"
|
position_type = "long"
|
||||||
debug_print(f"Range BUY signal: strength={strength:.2f}, stop=${stop:.2f}")
|
debug_print(f"Range BUY signal: strength={strength:.2f}, stop=${stop:.2f}")
|
||||||
|
|
||||||
if current_price >= upper.iloc[-1] and rsi_val > RSI_RANGE_OVERBOUGHT:
|
elif current_price >= upper.iloc[-1] and rsi_val > RSI_RANGE_OVERBOUGHT:
|
||||||
if REQUIRE_CANDLE_PATTERN and not bearish_pattern:
|
if REQUIRE_CANDLE_PATTERN and not bearish_pattern:
|
||||||
debug_print("Range sell rejected: candle pattern required")
|
debug_print("Range sell rejected: candle pattern required")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user