Rename method to custom_stoploss
This commit is contained in:
parent
277342f167
commit
9d5961e224
@ -23,7 +23,7 @@ E.g. `current_profit = 0.05` (5% profit) - stoploss returns `0.02` - then you "l
|
|||||||
``` python
|
``` python
|
||||||
use_custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
# TODO: Add full docstring here
|
# TODO: Add full docstring here
|
||||||
return 0.04
|
return 0.04
|
||||||
@ -47,7 +47,7 @@ Use the initial stoploss for the first 60 minutes, after this change to 10% trai
|
|||||||
``` python
|
``` python
|
||||||
use_custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
# TODO: Add full docstring here
|
# TODO: Add full docstring here
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ In this example, we'll trail the highest price with 10% trailing stoploss for `E
|
|||||||
``` python
|
``` python
|
||||||
use_custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
# TODO: Add full docstring here
|
# TODO: Add full docstring here
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ The below example sets absolute profit levels based on the current profit.
|
|||||||
``` python
|
``` python
|
||||||
use_custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
# TODO: Add full docstring here
|
# TODO: Add full docstring here
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ class IStrategy(ABC):
|
|||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
"""
|
"""
|
||||||
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
||||||
@ -555,7 +555,7 @@ class IStrategy(ABC):
|
|||||||
trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True)
|
trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True)
|
||||||
|
|
||||||
if self.use_custom_stoploss:
|
if self.use_custom_stoploss:
|
||||||
stop_loss_value = strategy_safe_wrapper(self.stoploss_value, default_retval=None
|
stop_loss_value = strategy_safe_wrapper(self.custom_stoploss, default_retval=None
|
||||||
)(pair=trade.pair, trade=trade,
|
)(pair=trade.pair, trade=trade,
|
||||||
current_time=current_time,
|
current_time=current_time,
|
||||||
current_rate=current_rate,
|
current_rate=current_rate,
|
||||||
|
@ -14,7 +14,7 @@ def bot_loop_start(self, **kwargs) -> None:
|
|||||||
|
|
||||||
use_custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
"""
|
"""
|
||||||
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from freqtrade.persistence.models import Trade
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
from freqtrade.persistence.models import Trade
|
||||||
|
|
||||||
from .strats.default_strategy import DefaultStrategy
|
from .strats.default_strategy import DefaultStrategy
|
||||||
|
|
||||||
|
|
||||||
@ -38,5 +40,5 @@ def test_default_strategy(result, fee):
|
|||||||
assert strategy.confirm_trade_exit(pair='ETH/BTC', trade=trade, order_type='limit', amount=0.1,
|
assert strategy.confirm_trade_exit(pair='ETH/BTC', trade=trade, order_type='limit', amount=0.1,
|
||||||
rate=20000, time_in_force='gtc', sell_reason='roi') is True
|
rate=20000, time_in_force='gtc', sell_reason='roi') is True
|
||||||
|
|
||||||
assert strategy.stoploss_value(pair='ETH/BTC', trade=trade, current_time=datetime.now(),
|
assert strategy.custom_stoploss(pair='ETH/BTC', trade=trade, current_time=datetime.now(),
|
||||||
current_rate=20_000, current_profit=0.05) == strategy.stoploss
|
current_rate=20_000, current_profit=0.05) == strategy.stoploss
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# pragma pylint: disable=missing-docstring, C0103
|
# pragma pylint: disable=missing-docstring, C0103
|
||||||
from freqtrade.strategy.interface import SellCheckTuple, SellType
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
@ -11,9 +10,10 @@ from pandas import DataFrame
|
|||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.configuration import TimeRange
|
||||||
from freqtrade.data.dataprovider import DataProvider
|
from freqtrade.data.dataprovider import DataProvider
|
||||||
from freqtrade.data.history import load_data
|
from freqtrade.data.history import load_data
|
||||||
from freqtrade.exceptions import OperationalException, StrategyError
|
from freqtrade.exceptions import StrategyError
|
||||||
from freqtrade.persistence import PairLocks, Trade
|
from freqtrade.persistence import PairLocks, Trade
|
||||||
from freqtrade.resolvers import StrategyResolver
|
from freqtrade.resolvers import StrategyResolver
|
||||||
|
from freqtrade.strategy.interface import SellCheckTuple, SellType
|
||||||
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
||||||
from tests.conftest import log_has, log_has_re
|
from tests.conftest import log_has, log_has_re
|
||||||
|
|
||||||
@ -329,9 +329,9 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
|
|||||||
strategy.trailing_stop = trailing
|
strategy.trailing_stop = trailing
|
||||||
strategy.trailing_stop_positive = -0.05
|
strategy.trailing_stop_positive = -0.05
|
||||||
strategy.use_custom_stoploss = custom
|
strategy.use_custom_stoploss = custom
|
||||||
original_stopvalue = strategy.stoploss_value
|
original_stopvalue = strategy.custom_stoploss
|
||||||
if custom_stop:
|
if custom_stop:
|
||||||
strategy.stoploss_value = custom_stop
|
strategy.custom_stoploss = custom_stop
|
||||||
|
|
||||||
now = arrow.utcnow().datetime
|
now = arrow.utcnow().datetime
|
||||||
sl_flag = strategy.stop_loss_reached(current_rate=trade.open_rate * (1 + profit), trade=trade,
|
sl_flag = strategy.stop_loss_reached(current_rate=trade.open_rate * (1 + profit), trade=trade,
|
||||||
@ -355,8 +355,7 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
|
|||||||
assert sl_flag.sell_flag is True
|
assert sl_flag.sell_flag is True
|
||||||
assert round(trade.stop_loss, 2) == adjusted2
|
assert round(trade.stop_loss, 2) == adjusted2
|
||||||
|
|
||||||
strategy.stoploss_value = original_stopvalue
|
strategy.custom_stoploss = original_stopvalue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_analyze_ticker_default(ohlcv_history, mocker, caplog) -> None:
|
def test_analyze_ticker_default(ohlcv_history, mocker, caplog) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user