Refactoring to use strategy based configuration
This commit is contained in:
@@ -83,7 +83,6 @@ Mandatory parameters are marked as **Required**, which means that they are requi
|
||||
| `stake_amount` | **Required.** Amount of crypto-currency your bot will use for each trade. Set it to `"unlimited"` to allow the bot to use all available balance. [More information below](#configuring-amount-per-trade). <br> **Datatype:** Positive float or `"unlimited"`.
|
||||
| `tradable_balance_ratio` | Ratio of the total account balance the bot is allowed to trade. [More information below](#configuring-amount-per-trade). <br>*Defaults to `0.99` 99%).*<br> **Datatype:** Positive float between `0.1` and `1.0`.
|
||||
| `available_capital` | Available starting capital for the bot. Useful when running multiple bots on the same exchange account.[More information below](#configuring-amount-per-trade). <br> **Datatype:** Positive float.
|
||||
| `base_stake_amount_ratio` | When using position adjustment with unlimited stakes, the strategy often requires that some funds are left for additional buy orders. You can define the ratio that the initial buy order can use from the calculated unlimited stake amount. [More information below](#configuring-amount-per-trade). <br>*Defaults to `1.0`.* <br> **Datatype:** Float (as ratio)
|
||||
| `amend_last_stake_amount` | Use reduced last stake amount if necessary. [More information below](#configuring-amount-per-trade). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||
| `last_stake_amount_min_ratio` | Defines minimum stake amount that has to be left and executed. Applies only to the last stake amount when it's amended to a reduced value (i.e. if `amend_last_stake_amount` is set to `true`). [More information below](#configuring-amount-per-trade). <br>*Defaults to `0.5`.* <br> **Datatype:** Float (as ratio)
|
||||
| `amount_reserve_percent` | Reserve some amount in min pair stake amount. The bot will reserve `amount_reserve_percent` + stoploss value when calculating min pair stake amount in order to avoid possible trade refusals. <br>*Defaults to `0.05` (5%).* <br> **Datatype:** Positive Float as ratio.
|
||||
@@ -173,7 +172,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
|
||||
| `user_data_dir` | Directory containing user data. <br> *Defaults to `./user_data/`*. <br> **Datatype:** String
|
||||
| `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 below. <br> **Datatype:** Boolean
|
||||
| `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 `true`.*<br> **Datatype:** Boolean
|
||||
|
||||
### Parameters in the strategy
|
||||
|
||||
@@ -198,6 +197,7 @@ Values set in the configuration file always overwrite values set in the strategy
|
||||
* `sell_profit_offset`
|
||||
* `ignore_roi_if_buy_signal`
|
||||
* `ignore_buying_expired_candle_after`
|
||||
* `position_adjustment_enable`
|
||||
|
||||
### Configuring amount per trade
|
||||
|
||||
@@ -594,15 +594,6 @@ export HTTPS_PROXY="http://addr:port"
|
||||
freqtrade
|
||||
```
|
||||
|
||||
### Understand position_adjustment_enable
|
||||
|
||||
The `position_adjustment_enable` configuration parameter enables the usage of `adjust_trade_position()` callback in strategy.
|
||||
For performance reasons, it's disabled by default, and freqtrade will show a warning message on startup if enabled.
|
||||
Enabling this does nothing unless the strategy also implements `adjust_trade_position()` callback.
|
||||
|
||||
See [the strategy callbacks](strategy-callbacks.md) for details on usage.
|
||||
|
||||
|
||||
## Next step
|
||||
|
||||
Now you have configured your config.json, the next step is to [start your bot](bot-usage.md).
|
||||
|
@@ -232,14 +232,13 @@ merged_frame = pd.concat(frames, axis=1)
|
||||
|
||||
## Adjust trade position
|
||||
|
||||
The `position_adjustment_enable` strategy property enables the usage of `adjust_trade_position()` callback in strategy.
|
||||
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 to manage risk with DCA (Dollar Cost Averaging) for example.
|
||||
The strategy is expected to return a stake_amount if and when an additional buy order should be made (position is increased).
|
||||
If there is not enough funds in the wallet then nothing will happen.
|
||||
Additional orders also mean additional fees and those orders don't count towards `max_open_trades`.
|
||||
Unlimited stake amount with trade position increasing is highly not recommended as your DCA orders would compete with your normal trade open orders.
|
||||
|
||||
!!! Note
|
||||
The `position_adjustment_enable` configuration parameter must be enabled to use adjust_trade_position callback in strategy.
|
||||
Using unlimited stake amount with DCA orders requires you to also implement `custom_stake_amount` callback to avoid allocating all funcds to initial order.
|
||||
|
||||
!!! Warning
|
||||
Stoploss is still calculated from the initial opening price, not averaged price.
|
||||
@@ -253,8 +252,21 @@ class DigDeeperStrategy(IStrategy):
|
||||
# Attempts to handle large drops with DCA. High stoploss is required.
|
||||
stoploss = -0.30
|
||||
|
||||
max_dca_orders = 3
|
||||
|
||||
# ... populate_* methods
|
||||
|
||||
# Let unlimited stakes leave funds open for DCA orders
|
||||
def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,
|
||||
proposed_stake: float, min_stake: float, max_stake: float,
|
||||
**kwargs) -> float:
|
||||
|
||||
if self.config['stake_amount'] == 'unlimited':
|
||||
return proposed_stake / 5.5
|
||||
|
||||
# Use default stake amount.
|
||||
return proposed_stake
|
||||
|
||||
def adjust_trade_position(self, pair: str, trade: Trade,
|
||||
current_time: datetime, current_rate: float, current_profit: float,
|
||||
**kwargs) -> Optional[float]:
|
||||
@@ -270,7 +282,7 @@ class DigDeeperStrategy(IStrategy):
|
||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||
:return float: Stake amount to adjust your trade
|
||||
"""
|
||||
|
||||
|
||||
if current_profit > -0.05:
|
||||
return None
|
||||
|
||||
@@ -285,9 +297,6 @@ class DigDeeperStrategy(IStrategy):
|
||||
|
||||
count_of_buys = 0
|
||||
for order in trade.orders:
|
||||
# Instantly stop when there's an open order
|
||||
if order.ft_is_open:
|
||||
return None
|
||||
if order.ft_order_side == 'buy' and order.status == "closed":
|
||||
count_of_buys += 1
|
||||
|
||||
@@ -298,7 +307,7 @@ class DigDeeperStrategy(IStrategy):
|
||||
# If that falles once again down to -5%, we buy 1.75x more
|
||||
# Total stake for this trade would be 1 + 1.25 + 1.5 + 1.75 = 5.5x of the initial allowed stake.
|
||||
# Hope you have a deep wallet!
|
||||
if 0 < count_of_buys <= 3:
|
||||
if 0 < count_of_buys <= self.max_dca_orders:
|
||||
try:
|
||||
stake_amount = self.wallets.get_trade_stake_amount(pair, None)
|
||||
stake_amount = stake_amount * (1 + (count_of_buys * 0.25))
|
||||
|
@@ -572,54 +572,10 @@ class AwesomeStrategy(IStrategy):
|
||||
|
||||
## Adjust trade position
|
||||
|
||||
`adjust_trade_position()` can be used to perform additional orders to manage risk with DCA (Dollar Cost Averaging).
|
||||
The `position_adjustment_enable` strategy property enables the usage of `adjust_trade_position()` callback in strategy.
|
||||
For performance reasons, it's disabled by default and freqtrade will show a warning message on startup if enabled.
|
||||
Enabling this does nothing unless the strategy also implements `adjust_trade_position()` callback.
|
||||
`adjust_trade_position()` can be used to perform additional orders, for example to manage risk with DCA (Dollar Cost Averaging).
|
||||
The strategy is expected to return a stake_amount if and when an additional buy order should be made (position is increased).
|
||||
If there is not enough funds in the wallet then nothing will happen.
|
||||
Additional orders also mean additional fees and those orders don't count towards `max_open_trades`.
|
||||
Unlimited stake amount with trade position increasing is highly not recommended as your DCA orders would compete with your normal trade open orders.
|
||||
|
||||
!!! Note
|
||||
Current implementation does not support decreasing position size with partial sales!
|
||||
|
||||
!!! Tip
|
||||
The `position_adjustment_enable` configuration parameter must be enabled to use adjust_trade_position callback in strategy.
|
||||
|
||||
!!! Warning
|
||||
Stoploss is still calculated from the initial opening price, not averaged price.
|
||||
So if you do 3 additional buys at -7% and have a stoploss at -10% then you will most likely trigger stoploss while the UI will be showing you an average profit of -3%.
|
||||
|
||||
``` python
|
||||
from freqtrade.persistence import Trade
|
||||
|
||||
|
||||
class AwesomeStrategy(IStrategy):
|
||||
|
||||
# ... populate_* methods
|
||||
|
||||
def adjust_trade_position(self, pair: str, trade: Trade,
|
||||
current_time: datetime, current_rate: float, current_profit: float,
|
||||
**kwargs) -> Optional[float]:
|
||||
"""
|
||||
Custom trade adjustment logic, returning the stake amount that a trade should be increased.
|
||||
This means extra buy orders with additional fees.
|
||||
|
||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||
|
||||
When not implemented by a strategy, returns None
|
||||
|
||||
:param pair: Pair that's currently analyzed
|
||||
:param trade: trade object.
|
||||
:param current_time: datetime object, containing the current datetime
|
||||
:param current_rate: Rate, calculated based on pricing settings in ask_strategy.
|
||||
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||
:return float: Stake amount to adjust your trade
|
||||
"""
|
||||
|
||||
# Example: If 10% loss / -10% profit then buy more the same amount we had before.
|
||||
if current_profit < -0.10:
|
||||
return trade.stake_amount
|
||||
|
||||
return None
|
||||
|
||||
```
|
||||
[See Advanced Strategies for an example](strategy-advanced.md#adjust-trade-position)
|
||||
|
Reference in New Issue
Block a user