]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(qav3): cleanup trade entry confirmation
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 12 Apr 2025 17:26:38 +0000 (19:26 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 12 Apr 2025 17:26:38 +0000 (19:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/strategies/QuickAdapterV3.py

index 2719a51ba84d50bf5925a03307872ad4c917d928..46ac9219bbb0dbedf7d676df7d599aa28356804b 100644 (file)
@@ -649,15 +649,17 @@ class QuickAdapterV3(IStrategy):
         if df.empty:
             return False
         last_candle = df.iloc[-1]
-        entry_price_fluctuation_threshold = (
-            last_candle["natr_label_period_candles"] * self.entry_natr_ratio
-        )
+        last_candle_close = last_candle["close"]
+        last_candle_natr = last_candle["natr_label_period_candles"]
+        if isna(last_candle_natr):
+            return False
+        entry_price_fluctuation_threshold = last_candle_natr * self.entry_natr_ratio
         if (
             side == "long"
-            and rate > last_candle["close"] * (1 + entry_price_fluctuation_threshold)
+            and rate > last_candle_close * (1 + entry_price_fluctuation_threshold)
         ) or (
             side == "short"
-            and rate < last_candle["close"] * (1 - entry_price_fluctuation_threshold)
+            and rate < last_candle_close * (1 - entry_price_fluctuation_threshold)
         ):
             return False