πStill Blocked by Orders? Try This Freqtrade Smart Order System
This article was produced by the Quantitative Trading Lab at https://www.itrade.icu. Visit for more benefits. In quantitative trading, order price and order timeout are key factors that determine trading efficiency and risk management. The Freqtrade bot provides several custom hooks to finely control buy and sell prices and the order lifecycle, preventing opportunity loss caused by unfavorable order execution or locked funds.
This article focuses on three functions:
custom_entry_price: Customize the buy order price to avoid orders being instantly filled or excessive cost.check_entry_timeout: Determine whether a buy order has timed out and cancel unfilled orders to release funds.check_exit_timeout: Determine whether a sell order has timed out to prevent long-standing inactive orders.
1. Custom Buy Order Price β custom_entry_price
custom_entry_priceIn Freqtrade, the default buy price is determined by the exchange's market price or the strategy's default limit price. However, precise control of order price is crucial in practice.
If the order price is too conservative, the buy may not execute quickly, missing good opportunities; if too high, the cost increases.
The custom_entry_price function allows you to customize the limit order price, making the buying logic more flexible.
Use Cases
Aggressive strategy: Use market or near-market price to ensure fast execution.
Conservative strategy: Set a slightly lower price for a better buying cost.
Hybrid strategy: Dynamically adjust price according to market volatility or other signals.
Example Code
Summary
This allows the strategy to adjust buy prices according to market conditions and capital management needs, effectively preventing instant fills or high costs.
2. Order Timeout Handling β check_entry_timeout & check_exit_timeout
check_entry_timeout & check_exit_timeoutDuring limit orders, the biggest concern is orders being "stuck," occupying funds without executing.
This not only affects capital turnover but may also miss better trading opportunities.
Freqtrade allows developers to define custom timeout rules through check_entry_timeout and check_exit_timeout.
Design Idea
High-priced coins (e.g., BTC/USDT): sensitive to capital, cancel if unfilled for a short period.
Mid-priced coins (e.g., BNB, LTC): moderate timeout.
Low-priced coins (e.g., SHIB, DOGE): longer timeout allowed due to volatility.
Example Code
Further Optimization
Adjust timeout dynamically according to market volatility.
Use order book depth or volume to decide whether to cancel.
Set different timeout rules for different strategies or coins.
3. Notes: Limit Order Configuration
custom_entry_price and the timeout functions only work with limit orders. Market or other order types will not trigger these functions.
Enable Limit Orders
In config.json:
Freqtrade will then use limit orders for buy/sell, ensuring these custom logics take effect.
Summary
Order price and timeout management are key to improving trade execution quality.
Use
custom_entry_priceto customize buy prices according to market conditions and strategy style.Use
check_entry_timeoutandcheck_exit_timeoutto prevent stuck orders and free up capital.With limit order configuration, these three form a complete order management system.
Proper order management prevents instant fills, long-standing orders, or missed better prices, making trading more stable and efficient.
Last updated