Changed workings so it only needs to timing-parameter, instead of also requiring a boolean value

This commit is contained in:
hoeckxer 2021-01-12 07:30:39 +01:00
parent b43ef474ad
commit e328182bd7
4 changed files with 6 additions and 11 deletions

View File

@ -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). <br>*Defaults to `true`.* <br> **Datatype:** Boolean | `ask_strategy.use_sell_signal` | Use sell signals produced by the strategy in addition to the `minimal_roi`. [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `true`.* <br> **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). <br>*Defaults to `false`.* <br> **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). <br>*Defaults to `false`.* <br> **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). <br>*Defaults to `false`.* <br> **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). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
| `ask_strategy.ignore_buying_expired_candle` | Enables usage of skipping buys on candles that are older than a specified period. <br>*Defaults to `False`* <br> **Datatype:** Boolean | `ask_strategy.ignore_buying_expired_candle_after` | Specifies the number of seconds until a buy signal is no longer used. <br> **Datatype:** Integer
| `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`. <br> **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).<br> **Datatype:** Dict | `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).<br> **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). <br> **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). <br> **Datatype:** Dict
| `exchange.name` | **Required.** Name of the exchange class to use. [List below](#user-content-what-values-for-exchangename). <br> **Datatype:** String | `exchange.name` | **Required.** Name of the exchange class to use. [List below](#user-content-what-values-for-exchangename). <br> **Datatype:** String
@ -146,7 +145,6 @@ Values set in the configuration file always overwrite values set in the strategy
* `use_sell_signal` (ask_strategy) * `use_sell_signal` (ask_strategy)
* `sell_profit_only` (ask_strategy) * `sell_profit_only` (ask_strategy)
* `ignore_roi_if_buy_signal` (ask_strategy) * `ignore_roi_if_buy_signal` (ask_strategy)
* `ignore_buying_expired_candle` (ask_strategy)
* `ignore_buying_expired_candle_after` (ask_strategy) * `ignore_buying_expired_candle_after` (ask_strategy)
### Configuring amount per trade ### 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. 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: 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 ``` jsonc
"ask_strategy":{ "ask_strategy":{
"ignore_buying_expired_candle" = true
"ignore_buying_expired_candle_after" = 300 # 5 minutes "ignore_buying_expired_candle_after" = 300 # 5 minutes
"price_side": "bid", "price_side": "bid",
// ... // ...

View File

@ -79,7 +79,6 @@ class StrategyResolver(IResolver):
("sell_profit_only", False, 'ask_strategy'), ("sell_profit_only", False, 'ask_strategy'),
("ignore_roi_if_buy_signal", False, 'ask_strategy'), ("ignore_roi_if_buy_signal", False, 'ask_strategy'),
("disable_dataframe_checks", False, None), ("disable_dataframe_checks", False, None),
("ignore_buying_expired_candle", None, 'ask_strategy'),
("ignore_buying_expired_candle_after", 0, 'ask_strategy') ("ignore_buying_expired_candle_after", 0, 'ask_strategy')
] ]
for attribute, default, subkey in attributes: for attribute, default, subkey in attributes:

View File

@ -113,9 +113,7 @@ class IStrategy(ABC):
# run "populate_indicators" only for new candle # run "populate_indicators" only for new candle
process_only_new_candles: bool = False process_only_new_candles: bool = False
# Don't buy on expired candles # Number of seconds after which the candle will no longer result in a buy on expired candles
ignore_buying_expired_candle: bool = False
# Number of seconds after which the candle will no longer result in a buy
ignore_buying_expired_candle_after: int = 0 ignore_buying_expired_candle_after: int = 0
# Disable checking the dataframe (converts the error into a warning message) # 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, def ignore_expired_candle(self, latest_date: datetime, current_time: datetime,
timeframe_seconds: int, buy: bool): 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)) time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds))
return time_delta.total_seconds() > self.ignore_buying_expired_candle_after return time_delta.total_seconds() > self.ignore_buying_expired_candle_after
else: else:

View File

@ -109,7 +109,6 @@ def test_get_signal_old_dataframe(default_conf, mocker, caplog, ohlcv_history):
def test_ignore_expired_candle(default_conf): def test_ignore_expired_candle(default_conf):
default_conf.update({'strategy': 'DefaultStrategy'}) default_conf.update({'strategy': 'DefaultStrategy'})
strategy = StrategyResolver.load_strategy(default_conf) strategy = StrategyResolver.load_strategy(default_conf)
strategy.ignore_buying_expired_candle = True
strategy.ignore_buying_expired_candle_after = 60 strategy.ignore_buying_expired_candle_after = 60
latest_date = datetime(2020, 12, 30, 7, 0, 0, tzinfo=timezone.utc) latest_date = datetime(2020, 12, 30, 7, 0, 0, tzinfo=timezone.utc)