Prepare protections for backtesting
This commit is contained in:
@@ -43,16 +43,21 @@ class StoplossGuard(IProtection):
|
||||
Evaluate recent trades
|
||||
"""
|
||||
look_back_until = date_now - timedelta(minutes=self._lookback_period)
|
||||
filters = [
|
||||
Trade.is_open.is_(False),
|
||||
Trade.close_date > look_back_until,
|
||||
or_(Trade.sell_reason == SellType.STOP_LOSS.value,
|
||||
and_(Trade.sell_reason == SellType.TRAILING_STOP_LOSS.value,
|
||||
Trade.close_profit < 0))
|
||||
]
|
||||
if pair:
|
||||
filters.append(Trade.pair == pair)
|
||||
trades = Trade.get_trades(filters).all()
|
||||
# filters = [
|
||||
# Trade.is_open.is_(False),
|
||||
# Trade.close_date > look_back_until,
|
||||
# or_(Trade.sell_reason == SellType.STOP_LOSS.value,
|
||||
# and_(Trade.sell_reason == SellType.TRAILING_STOP_LOSS.value,
|
||||
# Trade.close_profit < 0))
|
||||
# ]
|
||||
# if pair:
|
||||
# filters.append(Trade.pair == pair)
|
||||
# trades = Trade.get_trades(filters).all()
|
||||
|
||||
trades1 = Trade.get_trades_proxy(pair=pair, is_open=False, close_date=look_back_until)
|
||||
trades = [trade for trade in trades1 if trade.sell_reason == SellType.STOP_LOSS
|
||||
or (trade.sell_reason == SellType.TRAILING_STOP_LOSS
|
||||
and trade.close_profit < 0)]
|
||||
|
||||
if len(trades) > self._trade_limit:
|
||||
self.log_once(f"Trading stopped due to {self._trade_limit} "
|
||||
|
||||
Reference in New Issue
Block a user