From 5525fdae1a4211949d77fe3676dbd6f37e4fbe22 Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Wed, 19 Jan 2022 16:50:13 +0900 Subject: [PATCH] add max_buy_position_adjustment as attribute --- docs/configuration.md | 2 ++ docs/strategy-callbacks.md | 4 ++-- freqtrade/resolvers/strategy_resolver.py | 3 ++- freqtrade/strategy/interface.py | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 340ae2e72..3b7ae3c86 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -173,6 +173,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi | `dataformat_ohlcv` | Data format to use to store historical candle (OHLCV) data.
*Defaults to `json`*.
**Datatype:** String | `dataformat_trades` | Data format to use to store historical trades data.
*Defaults to `jsongz`*.
**Datatype:** String | `position_adjustment_enable` | Enables the strategy to use position adjustments (additional buys or sells). [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean +| `max_buy_position_adjustment` | Maximum additional buy(s) for each open trades on top of the first buy. [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `1`.*
**Datatype:** Positive Integer ### Parameters in the strategy @@ -198,6 +199,7 @@ Values set in the configuration file always overwrite values set in the strategy * `ignore_roi_if_buy_signal` * `ignore_buying_expired_candle_after` * `position_adjustment_enable` +* `max_buy_position_adjustment` ### Configuring amount per trade diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index 6edc549a4..f0f9a1853 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -611,7 +611,7 @@ class DigDeeperStrategy(IStrategy): # ... populate_* methods # Example specific variables - max_dca_orders = 3 + max_buy_position_adjustment = 3 # This number is explained a bit further down max_dca_multiplier = 5.5 @@ -663,7 +663,7 @@ class DigDeeperStrategy(IStrategy): # Total stake for this trade would be 1 + 1.25 + 1.5 + 1.75 = 5.5x of the initial allowed stake. # That is why max_dca_multiplier is 5.5 # Hope you have a deep wallet! - if 0 < count_of_buys <= self.max_dca_orders: + if 0 < count_of_buys <= self.max_buy_position_adjustment: try: # This returns first order stake size stake_amount = filled_buys[0].cost diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index 95177c000..d331bd893 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -97,7 +97,8 @@ class StrategyResolver(IResolver): ("sell_profit_offset", 0.0), ("disable_dataframe_checks", False), ("ignore_buying_expired_candle_after", 0), - ("position_adjustment_enable", False) + ("position_adjustment_enable", False), + ("max_buy_position_adjustment", 1) ] for attribute, default in attributes: StrategyResolver._override_attribute_helper(strategy, config, diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index c8fb24da1..5a095aed3 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -108,6 +108,7 @@ class IStrategy(ABC, HyperStrategyMixin): # Position adjustment is disabled by default position_adjustment_enable: bool = False + max_buy_position_adjustment: int = 1 # Number of seconds after which the candle will no longer result in a buy on expired candles ignore_buying_expired_candle_after: int = 0