]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(reforcexy): ensure model expiracy triggers open trades close
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 29 Sep 2025 16:56:11 +0000 (18:56 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 29 Sep 2025 16:56:11 +0000 (18:56 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
ReforceXY/user_data/strategies/RLAgentStrategy.py

index 4555f1bbfe3772e65776659baeea8100817f4a01..4d8849ba4f06d57af7a6a2a0af378aebca0f420c 100644 (file)
@@ -3,6 +3,7 @@ from functools import cached_property, reduce
 from typing import Any
 
 # import talib.abstract as ta
+from freqtrade.persistence import Trade
 from freqtrade.strategy import IStrategy
 from pandas import DataFrame
 
@@ -105,6 +106,16 @@ class RLAgentStrategy(IStrategy):
             reduce(lambda x, y: x & y, exit_short_conditions), "exit_short"
         ] = 1
 
+        last_candle = dataframe.iloc[-1]
+        if last_candle.get("do_predict") == 2:
+            trades = Trade.get_trades_proxy(pair=metadata.get("pair"), is_open=True)
+            for trade in trades:
+                last_index = dataframe.index[-1]
+                if trade.is_short:
+                    dataframe.at[last_index, "exit_short"] = 1
+                else:
+                    dataframe.at[last_index, "exit_long"] = 1
+
         return dataframe
 
     def is_short_allowed(self) -> bool: