From c38f8a0e6969ac1c1a719598101a9af9f22bc0d2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 12 Mar 2022 11:07:31 +0100 Subject: [PATCH] Update custom_sell() documentation --- docs/backtesting.md | 2 +- docs/bot-basics.md | 4 ++-- docs/leverage.md | 1 - docs/strategy-advanced.md | 6 +++--- docs/strategy-callbacks.md | 12 ++++++------ docs/strategy_migration.md | 21 +++++++++++++++++++++ 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/docs/backtesting.md b/docs/backtesting.md index 95722f506..a5d8726b4 100644 --- a/docs/backtesting.md +++ b/docs/backtesting.md @@ -533,7 +533,7 @@ freqtrade backtesting --strategy AwesomeStrategy --timeframe 1h --timeframe-deta ``` This will load 1h data as well as 5m data for the timeframe. The strategy will be analyzed with the 1h timeframe - and for every "open trade candle" (candles where a trade is open) the 5m data will be used to simulate intra-candle movements. -All callback functions (`custom_sell()`, `custom_stoploss()`, ... ) will be running for each 5m candle once the trade is opened (so 12 times in the above example of 1h timeframe, and 5m detailed timeframe). +All callback functions (`custom_exit()`, `custom_stoploss()`, ... ) will be running for each 5m candle once the trade is opened (so 12 times in the above example of 1h timeframe, and 5m detailed timeframe). `--timeframe-detail` must be smaller than the original timeframe, otherwise backtesting will fail to start. diff --git a/docs/bot-basics.md b/docs/bot-basics.md index 5294009cc..49dd8f5c7 100644 --- a/docs/bot-basics.md +++ b/docs/bot-basics.md @@ -35,7 +35,7 @@ By default, loop runs every few seconds (`internals.process_throttle_secs`) and * Calls `check_buy_timeout()` strategy callback for open buy orders. * Calls `check_sell_timeout()` strategy callback for open sell orders. * Verifies existing positions and eventually places sell orders. - * Considers stoploss, ROI and sell-signal, `custom_sell()` and `custom_stoploss()`. + * Considers stoploss, ROI and sell-signal, `custom_exit()` and `custom_stoploss()`. * Determine sell-price based on `ask_strategy` configuration setting or by using the `custom_exit_price()` callback. * Before a sell order is placed, `confirm_trade_exit()` strategy callback is called. * Check position adjustments for open trades if enabled by calling `adjust_trade_position()` and place additional order if required. @@ -62,7 +62,7 @@ This loop will be repeated again and again until the bot is stopped. * Determine stake size by calling the `custom_stake_amount()` callback. * In Margin and Futures mode, `leverage()` strategy callback is called to determine the desired leverage. * Check position adjustments for open trades if enabled and call `adjust_trade_position()` to determine if an additional order is requested. - * Call `custom_stoploss()` and `custom_sell()` to find custom exit points. + * Call `custom_stoploss()` and `custom_exit()` to find custom exit points. * For sells based on sell-signal and custom-sell: Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle). * Check for Order timeouts, either via the `unfilledtimeout` configuration, or via `check_buy_timeout()` / `check_sell_timeout()` strategy callbacks. * Generate backtest report output diff --git a/docs/leverage.md b/docs/leverage.md index 78d93dbed..852d4a8c4 100644 --- a/docs/leverage.md +++ b/docs/leverage.md @@ -104,4 +104,3 @@ All Fees are included in `current_profit` calculations during the trade. #### Futures mode Funding fees are either added or subtracted from the total amount of a trade - diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index 623e6cdfe..8fa5c1612 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -80,7 +80,7 @@ class AwesomeStrategy(IStrategy): ## Enter Tag When your strategy has multiple buy signals, you can name the signal that triggered. -Then you can access you buy signal on `custom_sell` +Then you can access you buy signal on `custom_exit` ```python def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: @@ -93,8 +93,8 @@ def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFram return dataframe -def custom_sell(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, - current_profit: float, **kwargs): +def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, + current_profit: float, **kwargs): dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) last_candle = dataframe.iloc[-1].squeeze() if trade.enter_tag == 'buy_signal_rsi' and last_candle['rsi'] > 80: diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index 54920b69f..d7aa7dfc7 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -9,10 +9,10 @@ Currently available callbacks: * [`bot_loop_start()`](#bot-loop-start) * [`custom_stake_amount()`](#custom-stake-size) -* [`custom_sell()`](#custom-sell-signal) +* [`custom_exit()`](#custom-exit-signal) * [`custom_stoploss()`](#custom-stoploss) * [`custom_entry_price()` and `custom_exit_price()`](#custom-order-price-rules) -* [`check_buy_timeout()` and `check_sell_timeout()](#custom-order-timeout-rules) +* [`check_buy_timeout()` and `check_sell_timeout()`](#custom-order-timeout-rules) * [`confirm_trade_entry()`](#trade-entry-buy-order-confirmation) * [`confirm_trade_exit()`](#trade-exit-sell-order-confirmation) * [`adjust_trade_position()`](#adjust-trade-position) @@ -79,15 +79,15 @@ Freqtrade will fall back to the `proposed_stake` value should your code raise an !!! Tip Returning `0` or `None` will prevent trades from being placed. -## Custom sell signal +## Custom exit signal Called for open trade every throttling iteration (roughly every 5 seconds) until a trade is closed. Allows to define custom sell signals, indicating that specified position should be sold. This is very useful when we need to customize sell conditions for each individual trade, or if you need trade data to make an exit decision. -For example you could implement a 1:2 risk-reward ROI with `custom_sell()`. +For example you could implement a 1:2 risk-reward ROI with `custom_exit()`. -Using custom_sell() signals in place of stoploss though *is not recommended*. It is a inferior method to using `custom_stoploss()` in this regard - which also allows you to keep the stoploss on exchange. +Using custom_exit() signals in place of stoploss though *is not recommended*. It is a inferior method to using `custom_stoploss()` in this regard - which also allows you to keep the stoploss on exchange. !!! Note Returning a (none-empty) `string` or `True` from this method is equal to setting sell signal on a candle at specified time. This method is not called when sell signal is set already, or if sell signals are disabled (`use_sell_signal=False` or `sell_profit_only=True` while profit is below `sell_profit_offset`). `string` max length is 64 characters. Exceeding this limit will cause the message to be truncated to 64 characters. @@ -96,7 +96,7 @@ An example of how we can use different indicators depending on the current profi ``` python class AwesomeStrategy(IStrategy): - def custom_sell(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float, + def custom_exit(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float, current_profit: float, **kwargs): dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) last_candle = dataframe.iloc[-1].squeeze() diff --git a/docs/strategy_migration.md b/docs/strategy_migration.md index 6bd283808..4d6de440f 100644 --- a/docs/strategy_migration.md +++ b/docs/strategy_migration.md @@ -10,6 +10,7 @@ If you intend on using markets other than spot markets, please migrate your stra * Strategy methods: * `populate_buy_trend()` -> `populate_entry_trend()` * `populate_sell_trend()` -> `populate_exit_trend()` + * `custom_sell()` -> `custom_exit()` * Dataframe columns: * `buy` -> `enter_long` * `sell` -> `exit_long` @@ -102,6 +103,26 @@ def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame Please refer to the [Strategy documentation](strategy-customization.md#exit-signal-rules) on how to enter and exit short trades. +### `custom_sell` + +``` python hl_lines="2" +class AwesomeStrategy(IStrategy): + def custom_sell(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float, + current_profit: float, **kwargs): + dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) + last_candle = dataframe.iloc[-1].squeeze() + # ... +``` + +``` python hl_lines="2" +class AwesomeStrategy(IStrategy): + def custom_exit(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float, + current_profit: float, **kwargs): + dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) + last_candle = dataframe.iloc[-1].squeeze() + # ... +``` + ### Custom-stake-amount New string argument `side` - which can be either `"long"` or `"short"`.