Update setting to max_entry_position_adjustment
This commit is contained in:
parent
0fa7986369
commit
002226f5fd
@ -173,7 +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. <br> *Defaults to `json`*. <br> **Datatype:** String
|
||||
| `dataformat_trades` | Data format to use to store historical trades data. <br> *Defaults to `jsongz`*. <br> **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). <br> [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.*<br> **Datatype:** Boolean
|
||||
| `max_buy_position_adjustment` | Maximum additional buy(s) for each open trade on top of the first buy. Set it to `-1` for unlimited additional buys. [More information here](strategy-callbacks.md#adjust-trade-position). <br> [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `-1`.*<br> **Datatype:** Positive Integer or -1
|
||||
| `max_entry_position_adjustment` | Maximum additional buy(s) for each open trade on top of the first entry Order. Set it to `-1` for unlimited additional additional orders. [More information here](strategy-callbacks.md#adjust-trade-position). <br> [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `-1`.*<br> **Datatype:** Positive Integer or -1
|
||||
|
||||
### Parameters in the strategy
|
||||
|
||||
@ -199,7 +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`
|
||||
* `max_entry_position_adjustment`
|
||||
|
||||
### Configuring amount per trade
|
||||
|
||||
|
@ -579,13 +579,13 @@ The `position_adjustment_enable` strategy property enables the usage of `adjust_
|
||||
For performance reasons, it's disabled by default and freqtrade will show a warning message on startup if enabled.
|
||||
`adjust_trade_position()` can be used to perform additional orders, for example to manage risk with DCA (Dollar Cost Averaging).
|
||||
|
||||
`max_buy_position_adjustment` property is used to limit the number of additional buys per trade (on top of the first buy) that the bot can execute. By default, the value is -1 which means the bot have no limit on number of adjustment buys.
|
||||
`max_entry_position_adjustment` property is used to limit the number of additional buys per trade (on top of the first buy) that the bot can execute. By default, the value is -1 which means the bot have no limit on number of adjustment buys.
|
||||
|
||||
The strategy is expected to return a stake_amount (in stake currency) between `min_stake` and `max_stake` if and when an additional buy order should be made (position is increased).
|
||||
If there are not enough funds in the wallet (the return value is above `max_stake`) then the signal will be ignored.
|
||||
Additional orders also result in additional fees and those orders don't count towards `max_open_trades`.
|
||||
|
||||
This callback is **not** called when there is an open order (either buy or sell) waiting for execution, or when you have reached the maximum amount of extra buys that you have set on `max_buy_position_adjustment`.
|
||||
This callback is **not** called when there is an open order (either buy or sell) waiting for execution, or when you have reached the maximum amount of extra buys that you have set on `max_entry_position_adjustment`.
|
||||
`adjust_trade_position()` is called very frequently for the duration of a trade, so you must keep your implementation as performant as possible.
|
||||
|
||||
!!! Note "About stake size"
|
||||
@ -616,7 +616,7 @@ class DigDeeperStrategy(IStrategy):
|
||||
# ... populate_* methods
|
||||
|
||||
# Example specific variables
|
||||
max_buy_position_adjustment = 3
|
||||
max_entry_position_adjustment = 3
|
||||
# This number is explained a bit further down
|
||||
max_dca_multiplier = 5.5
|
||||
|
||||
|
@ -373,7 +373,7 @@ CONF_SCHEMA = {
|
||||
'default': 'jsongz'
|
||||
},
|
||||
'position_adjustment_enable': {'type': 'boolean', 'default': False},
|
||||
'max_buy_position_adjustment': {'type': ['integer', 'number'], 'minimum': -1},
|
||||
'max_entry_position_adjustment': {'type': ['integer', 'number'], 'minimum': -1},
|
||||
},
|
||||
'definitions': {
|
||||
'exchange': {
|
||||
|
@ -471,13 +471,13 @@ class FreqtradeBot(LoggingMixin):
|
||||
If the strategy triggers the adjustment, a new order gets issued.
|
||||
Once that completes, the existing trade is modified to match new data.
|
||||
"""
|
||||
if self.strategy.max_buy_position_adjustment > -1:
|
||||
if self.strategy.max_entry_position_adjustment > -1:
|
||||
count_of_buys = trade.nr_of_successful_buys
|
||||
if count_of_buys > self.strategy.max_buy_position_adjustment:
|
||||
logger.debug(f"Max adjustment buy for {trade.pair} has been reached.")
|
||||
if count_of_buys > self.strategy.max_entry_position_adjustment:
|
||||
logger.debug(f"Max adjustment entries for {trade.pair} has been reached.")
|
||||
return
|
||||
else:
|
||||
logger.debug("Max adjustment buy is set to unlimited.")
|
||||
logger.debug("Max adjustment entries is set to unlimited.")
|
||||
current_rate = self.exchange.get_rate(trade.pair, refresh=True, side="buy")
|
||||
current_profit = trade.calc_profit_ratio(current_rate)
|
||||
|
||||
|
@ -382,9 +382,9 @@ class Backtesting:
|
||||
# Check if we need to adjust our current positions
|
||||
if self.strategy.position_adjustment_enable:
|
||||
check_adjust_buy = True
|
||||
if self.strategy.max_buy_position_adjustment > -1:
|
||||
if self.strategy.max_entry_position_adjustment > -1:
|
||||
count_of_buys = trade.nr_of_successful_buys
|
||||
check_adjust_buy = (count_of_buys <= self.strategy.max_buy_position_adjustment)
|
||||
check_adjust_buy = (count_of_buys <= self.strategy.max_entry_position_adjustment)
|
||||
if check_adjust_buy:
|
||||
trade = self._get_adjust_trade_entry_for_candle(trade, sell_row)
|
||||
|
||||
|
@ -98,7 +98,7 @@ class StrategyResolver(IResolver):
|
||||
("disable_dataframe_checks", False),
|
||||
("ignore_buying_expired_candle_after", 0),
|
||||
("position_adjustment_enable", False),
|
||||
("max_buy_position_adjustment", -1),
|
||||
("max_entry_position_adjustment", -1),
|
||||
]
|
||||
for attribute, default in attributes:
|
||||
StrategyResolver._override_attribute_helper(strategy, config,
|
||||
|
@ -174,7 +174,7 @@ class ShowConfig(BaseModel):
|
||||
state: str
|
||||
runmode: str
|
||||
position_adjustment_enable: bool
|
||||
max_buy_position_adjustment: int
|
||||
max_entry_position_adjustment: int
|
||||
|
||||
|
||||
class TradeSchema(BaseModel):
|
||||
|
@ -138,9 +138,10 @@ class RPC:
|
||||
'state': str(botstate),
|
||||
'runmode': config['runmode'].value,
|
||||
'position_adjustment_enable': config.get('position_adjustment_enable', False),
|
||||
'max_buy_position_adjustment': (config['max_buy_position_adjustment']
|
||||
if config['max_buy_position_adjustment'] != float('inf')
|
||||
else -1)
|
||||
'max_entry_position_adjustment': (
|
||||
config['max_entry_position_adjustment']
|
||||
if config['max_entry_position_adjustment'] != float('inf')
|
||||
else -1)
|
||||
}
|
||||
return val
|
||||
|
||||
@ -251,7 +252,7 @@ class RPC:
|
||||
profit_str
|
||||
]
|
||||
if self._config.get('position_adjustment_enable', False):
|
||||
max_buy = self._config['max_buy_position_adjustment'] + 1
|
||||
max_buy = self._config['max_entry_position_adjustment'] + 1
|
||||
filled_buys = trade.nr_of_successful_buys
|
||||
detail_trade.append(f"{filled_buys}/{max_buy}")
|
||||
trades_list.append(detail_trade)
|
||||
|
@ -1350,7 +1350,7 @@ class Telegram(RPCHandler):
|
||||
if val['position_adjustment_enable']:
|
||||
pa_info = (
|
||||
f"*Position adjustment:* On\n"
|
||||
f"*Max buy position adjustment:* `{val['max_buy_position_adjustment']}`\n"
|
||||
f"*Max enter position adjustment:* `{val['max_entry_position_adjustment']}`\n"
|
||||
)
|
||||
else:
|
||||
pa_info = "*Position adjustment:* Off\n"
|
||||
|
@ -108,7 +108,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
||||
|
||||
# Position adjustment is disabled by default
|
||||
position_adjustment_enable: bool = False
|
||||
max_buy_position_adjustment: int = -1
|
||||
max_entry_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
|
||||
|
@ -4570,7 +4570,7 @@ def test_process_open_trade_positions_exception(mocker, default_conf_usdt, fee,
|
||||
def test_check_and_call_adjust_trade_position(mocker, default_conf_usdt, fee, caplog) -> None:
|
||||
default_conf_usdt.update({
|
||||
"position_adjustment_enable": True,
|
||||
"max_buy_position_adjustment": 0,
|
||||
"max_entry_position_adjustment": 0,
|
||||
})
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||
|
||||
@ -4578,4 +4578,4 @@ def test_check_and_call_adjust_trade_position(mocker, default_conf_usdt, fee, ca
|
||||
caplog.set_level(logging.DEBUG)
|
||||
|
||||
freqtrade.process_open_trade_positions()
|
||||
assert log_has_re(r"Max adjustment buy for .* has been reached\.", caplog)
|
||||
assert log_has_re(r"Max adjustment entries for .* has been reached\.", caplog)
|
||||
|
Loading…
Reference in New Issue
Block a user