def _fit_live_predictions_candles(self) -> int:
return get_fit_live_predictions_candles(self.config.get("freqai"), logger)
+ @staticmethod
+ def _is_unlimited_max_open_trades(max_open_trades: int | float) -> bool:
+ return max_open_trades == -1 or max_open_trades == math.inf
+
@cached_property
def protections(self) -> list[dict[str, Any]]:
fit_live_predictions_candles = self._fit_live_predictions_candles
stoploss_stop_duration_candles,
fit_live_predictions_candles,
)
- max_open_trades = int(self.config.get("max_open_trades", 0))
- stoploss_trade_limit = min(
- max(
- 2,
- int(round(lookback_period_candles / max(1, trade_duration_candles))),
- ),
- max(2, int(round(max_open_trades * 0.75))),
+ max_open_trades = self.config.get("max_open_trades", 0)
+ unlimited_max_open_trades = QuickAdapterV3._is_unlimited_max_open_trades(
+ max_open_trades
+ )
+ estimated_trade_limit = max(
+ 2,
+ int(round(lookback_period_candles / max(1, trade_duration_candles))),
)
+ if unlimited_max_open_trades:
+ stoploss_trade_limit = estimated_trade_limit
+ drawdown_trade_limit = 2 * estimated_trade_limit
+ else:
+ max_open_trades = int(max_open_trades)
+ stoploss_trade_limit = min(
+ estimated_trade_limit,
+ max(2, int(round(max_open_trades * 0.75))),
+ )
+ drawdown_trade_limit = 2 * max_open_trades
protections_list = []
{
"method": "MaxDrawdown",
"lookback_period_candles": lookback_period_candles,
- "trade_limit": 2 * max_open_trades,
+ "trade_limit": drawdown_trade_limit,
"stop_duration_candles": drawdown_stop_duration_candles,
"max_allowed_drawdown": drawdown["max_allowed_drawdown"],
}
@property
def max_open_trades_per_side(self) -> int:
max_open_trades = self.config.get("max_open_trades", 0)
- if max_open_trades < 0:
+ if QuickAdapterV3._is_unlimited_max_open_trades(max_open_trades):
return -1
if self.is_short_allowed():
if max_open_trades % 2 == 1:
f"[{pair}] Denied short {QuickAdapterV3._ORDER_ENTRY}: shorting not allowed"
)
return False
- if Trade.get_open_trade_count() >= self.config.get("max_open_trades", 0):
+ max_open_trades = self.config.get("max_open_trades", 0)
+ if (
+ not QuickAdapterV3._is_unlimited_max_open_trades(max_open_trades)
+ and Trade.get_open_trade_count() >= max_open_trades
+ ):
return False
max_open_trades_per_side = self.max_open_trades_per_side
if max_open_trades_per_side >= 0: