mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
fix: Improve safety of custom_stop return validation
If the return is inf or NaN freqtrade should not fail closes #10349
This commit is contained in:
parent
4f43e59643
commit
b7f180ab3f
|
@ -165,7 +165,9 @@ E.g. If the `current_rate` is 200 USD, then returning `0.02` will set the stoplo
|
|||
During backtesting, `current_rate` (and `current_profit`) are provided against the candle's high (or low for short trades) - while the resulting stoploss is evaluated against the candle's low (or high for short trades).
|
||||
|
||||
The absolute value of the return value is used (the sign is ignored), so returning `0.05` or `-0.05` have the same result, a stoploss 5% below the current price.
|
||||
Returning None will be interpreted as "no desire to change", and is the only safe way to return when you'd like to not modify the stoploss.
|
||||
Returning `None` will be interpreted as "no desire to change", and is the only safe way to return when you'd like to not modify the stoploss.
|
||||
`NaN` and `inf` values are considered invalid and will be ignored (identical to `None`).
|
||||
|
||||
|
||||
Stoploss on exchange works similar to `trailing_stop`, and the stoploss on exchange is updated as configured in `stoploss_on_exchange_interval` ([More details about stoploss on exchange](stoploss.md#stop-loss-on-exchangefreqtrade)).
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ This module defines the interface to apply for strategies
|
|||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from math import isinf, isnan
|
||||
from typing import Dict, List, Optional, Tuple, Union
|
||||
|
||||
from pandas import DataFrame
|
||||
|
@ -1423,7 +1424,9 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
after_fill=after_fill,
|
||||
)
|
||||
# Sanity check - error cases will return None
|
||||
if stop_loss_value_custom:
|
||||
if stop_loss_value_custom and not (
|
||||
isnan(stop_loss_value_custom) or isinf(stop_loss_value_custom)
|
||||
):
|
||||
stop_loss_value = stop_loss_value_custom
|
||||
trade.adjust_stop_loss(
|
||||
bound or current_rate, stop_loss_value, allow_refresh=after_fill
|
||||
|
|
Loading…
Reference in New Issue
Block a user