πSell Only When You Should! Freqtrade Quantitative Custom Exit Guide β Precise Exits, Profit Without
This article was produced by the Quantitative Trading Lab at https://www.itrade.icu. Visit for more benefits. In automated trading, exiting a trade is even more important than entering.
Freqtradeprovides two functions to help you build smarter sell strategies:
custom_exit: Controls whether to exit at market pricecustom_exit_price: Controls the limit price for exit
β³οΈ Function 1: custom_exit β Control Whether to Sell (Market Order)
custom_exit β Control Whether to Sell (Market Order)Overview
custom_exit() determines whether to exit immediately at market price. Use it when you want to:
Sell when reaching a target profit (take profit)
Stop loss when exceeding a threshold
Exit based on time or external signals
π§ͺ Example 1: 10% Take Profit, 5% Stop Loss
A common exit strategy: Sell if profit > 10%; stop loss if loss > 5%; otherwise, hold.
def custom_exit(self, trade, current_time, current_rate, current_profit, **kwargs) -> float | bool:
"""
Logic:
- Current profit > 10%, sell immediately (take profit)
- Current profit < -5%, sell immediately (stop loss)
- Otherwise, hold
"""
if current_profit > 0.10:
return True
if current_profit < -0.05:
return True
return Falseβ Note: Returning
Truemeans βsell now,βFalsemeans βhold.β
β³οΈ Function 2: custom_exit_price β Set Limit Exit Price
custom_exit_price β Set Limit Exit PriceOverview
custom_exit_price() does not decide whether to exit; it sets the desired limit price. Useful for:
Placing a slightly higher sell order to maximize profit
Custom limit order exit strategies
Getting a better price than market, though execution may be slower
π§ͺ Example 2: Limit Sell 1% Above Current Price
β οΈ Notes
Make sure "exit": "limit" is set in order_types:
π Can Both Functions Be Used Together?
Yes, and it works well:
custom_exit_price: sets a limit order firstIf the price doesnβt fill in time, or market moves sharplyβ¦
custom_exittriggers a market exit to lock in profit or stop loss
π§ͺ Example 3: Limit + Forced Exit for Extra Profit
π Usage & Configuration Requirements
To make both functions work correctly, configure config.json:
π Comparison Table: custom_exit vs custom_exit_price
custom_exit vs custom_exit_priceFeature
custom_exit
custom_exit_price
Exit Type
Market Order
Limit Order
Immediate Exit
β Yes
β No
Execution Speed
Fast (may slip)
Slower (better price)
Return Value
True / False / float
float or None
Prerequisite
None
Must enable limit orders
Recommended Use
Stop loss, fast take profit
Wait for higher price, slow arbitrage
π― Summary Tips
Want to sell fast? Use
custom_exitWant to sell smart? Use
custom_exit_priceCombine both: place a limit order while keeping a safety exit line
πNext Preview: π Chapter 3: Smart Stop Loss β Using custom_stoploss + trailing_stop Together Learn how to implement trailing stops, breakeven exits, and automated profit protection!
If helpful, please like + save to support our updates π
Last updated