From e328182bd7d3bd40f850bb26179f97e868786ada Mon Sep 17 00:00:00 2001 From: hoeckxer Date: Tue, 12 Jan 2021 07:30:39 +0100 Subject: [PATCH] Changed workings so it only needs to timing-parameter, instead of also requiring a boolean value --- docs/configuration.md | 7 ++----- freqtrade/resolvers/strategy_resolver.py | 1 - freqtrade/strategy/interface.py | 8 ++++---- tests/strategy/test_interface.py | 1 - 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 6ae37e7b3..93693c919 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -74,8 +74,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi | `ask_strategy.use_sell_signal` | Use sell signals produced by the strategy in addition to the `minimal_roi`. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `true`.*
**Datatype:** Boolean | `ask_strategy.sell_profit_only` | Wait until the bot makes a positive profit before taking a sell decision. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean | `ask_strategy.ignore_roi_if_buy_signal` | Do not sell if the buy signal is still active. This setting takes preference over `minimal_roi` and `use_sell_signal`. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean -| `ask_strategy.ignore_buying_expired_candle` | Enables usage of skipping buys on candles that are older than a specified period.
*Defaults to `False`*
**Datatype:** Boolean -| `ask_strategy.ignore_buying_expired_candle_after` | Specifies the number of seconds until a buy signal is no longer used when setting `ignore_buying_expired_candle`.
**Datatype:** Integer +| `ask_strategy.ignore_buying_expired_candle_after` | Specifies the number of seconds until a buy signal is no longer used.
**Datatype:** Integer | `order_types` | Configure order-types depending on the action (`"buy"`, `"sell"`, `"stoploss"`, `"stoploss_on_exchange"`). [More information below](#understand-order_types). [Strategy Override](#parameters-in-the-strategy).
**Datatype:** Dict | `order_time_in_force` | Configure time in force for buy and sell orders. [More information below](#understand-order_time_in_force). [Strategy Override](#parameters-in-the-strategy).
**Datatype:** Dict | `exchange.name` | **Required.** Name of the exchange class to use. [List below](#user-content-what-values-for-exchangename).
**Datatype:** String @@ -146,7 +145,6 @@ Values set in the configuration file always overwrite values set in the strategy * `use_sell_signal` (ask_strategy) * `sell_profit_only` (ask_strategy) * `ignore_roi_if_buy_signal` (ask_strategy) -* `ignore_buying_expired_candle` (ask_strategy) * `ignore_buying_expired_candle_after` (ask_strategy) ### Configuring amount per trade @@ -679,13 +677,12 @@ freqtrade When working with larger timeframes (for example 1h or more) and using a low `max_open_trades` value, the last candle can be processed as soon as a trade slot becomes available. When processing the last candle, this can lead to a situation where it may not be desirable to use the buy signal on that candle. For example, when using a condition in your strategy where you use a cross-over, that point may have passed too long ago for you to start a trade on it. -In these situations, you can enable the functionality to ignore candles that are beyond a specified period by setting `ask_strategy.ignore_buying_expired_candle` to `true`. After this, you can set `ask_strategy.ignore_buying_expired_candle_after` to the number of seconds after which the candle becomes expired. +In these situations, you can enable the functionality to ignore candles that are beyond a specified period by setting `ask_strategy.ignore_buying_expired_candle_after` to a positive number, indicating the number of seconds after which the candle becomes expired. For example, if your strategy is using a 1h timeframe, and you only want to buy within the first 5 minutes when a new candle comes in, you can add the following configuration to your strategy: ``` jsonc "ask_strategy":{ - "ignore_buying_expired_candle" = true "ignore_buying_expired_candle_after" = 300 # 5 minutes "price_side": "bid", // ... diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index 5872d95a6..3b7374326 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -79,7 +79,6 @@ class StrategyResolver(IResolver): ("sell_profit_only", False, 'ask_strategy'), ("ignore_roi_if_buy_signal", False, 'ask_strategy'), ("disable_dataframe_checks", False, None), - ("ignore_buying_expired_candle", None, 'ask_strategy'), ("ignore_buying_expired_candle_after", 0, 'ask_strategy') ] for attribute, default, subkey in attributes: diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index b9d05f64f..57dcdeb3c 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -113,9 +113,7 @@ class IStrategy(ABC): # run "populate_indicators" only for new candle process_only_new_candles: bool = False - # Don't buy on expired candles - ignore_buying_expired_candle: bool = False - # Number of seconds after which the candle will no longer result in a buy + # Number of seconds after which the candle will no longer result in a buy on expired candles ignore_buying_expired_candle_after: int = 0 # Disable checking the dataframe (converts the error into a warning message) @@ -491,7 +489,9 @@ class IStrategy(ABC): def ignore_expired_candle(self, latest_date: datetime, current_time: datetime, timeframe_seconds: int, buy: bool): - if self.ignore_buying_expired_candle and buy: + if self.ignore_buying_expired_candle_after \ + and self.ignore_buying_expired_candle_after > 0\ + and buy: time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds)) return time_delta.total_seconds() > self.ignore_buying_expired_candle_after else: diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index a3969d91b..f158a1518 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -109,7 +109,6 @@ def test_get_signal_old_dataframe(default_conf, mocker, caplog, ohlcv_history): def test_ignore_expired_candle(default_conf): default_conf.update({'strategy': 'DefaultStrategy'}) strategy = StrategyResolver.load_strategy(default_conf) - strategy.ignore_buying_expired_candle = True strategy.ignore_buying_expired_candle_after = 60 latest_date = datetime(2020, 12, 30, 7, 0, 0, tzinfo=timezone.utc)