π Chapter 4: "How to Test Strategies Reliably? Freqtrade Backtesting Command Full Guide"
Backtesting is one of the most critical steps in strategy development.
By simulating strategies on historical market data, you can effectively evaluate their performance and determine if they are worth deploying to live trading.
This article provides a detailed guide to Freqtrade's backtesting command, including usage, common parameters, data handling, result analysis, multi-process acceleration, Docker usage, and more.
π Want to Learn Quantitative Trading?
π Click to visit: https://www.itrade.icu
Here you'll find Freqtrade beginner tutorials, strategy case studies, indicator analysis, and more to help you master quantitative trading skills effortlessly!
π 1. What is Backtesting? Why is it Important?
Backtesting is the process of running your strategy through historical data to simulate "hypothetical trades", with the goal of understanding how it would have performed in past market conditions.
A quality backtest can answer these key questions:
- Is the profit-loss ratio reasonable?
- Is the win rate sufficiently stable?
- Is there overfitting? (May fail in the future)
- Which parameters have the most significant impact on returns?
π 2. Basic Backtesting Command Structure
freqtrade backtesting \
--config user_data/config.json \
--strategy MyStrategy \
--timeframe 15m \
--timerange 20220101-20230701
Parameter Breakdown:
| Parameter | Description |
|---|---|
--config |
Specify config file path (contains pairs, timeframes, etc.) |
--strategy |
Strategy class name to use |
--timeframe |
Timeframe (e.g., 15m, 1h) |
--timerange |
Backtest period (format: YYYYMMDD-YYYYMMDD) |
Optional Parameters:
| Parameter | Description |
|-------------------|--------------------------|
| --export | Export detailed trades to CSV |
| --stats-file | Output results stats to JSON file |
| --processes | Launch multiple processes for parallel backtesting (improves performance) |
π‘ 3. Pre-Backtesting Checklist
Backtesting isn't just about running a command. Ensure these items are ready:
- β Historical data for the corresponding timeframe has been downloaded:
freqtrade download-data --timeframes 15m --timerange 20220101-20230701
- β
Strategy file is placed in
user_data/strategies/directory with correct class name. - β
config.jsonsettings are correct, including:- Correct trading pairs
- Correct exchange settings
-
stake_currencyset to USDT, BTC, etc.
π§ͺ 4. Backtesting Results Output Explanation
After backtesting completes, Freqtrade outputs logs containing the following information:
| Metric | Description |
|---|---|
Total profit |
Strategy's final total return (net value) |
Total trades |
Total number of trades during backtest |
Win / loss ratio |
Win rate (profitable/loss trades ratio) |
Sharpe Ratio |
Risk-adjusted return |
Avg trade duration |
Average holding time |
Drawdown |
Maximum drawdown |
Profit factor |
Profit factor (profits/losses) |
πΌοΈ 5. Graphical Backtest Display (backtesting-show)
Freqtrade provides a visualization tool backtesting-show to view entry/exit points and strategy behavior:
freqtrade backtesting-show \
--config user_data/config.json
π Displays profit curves, trade markers, position information, etc.
π§© 6. Common Backtesting Issues and Solutions
| Issue | Possible Causes |
|---|---|
| No trades in backtest | Strategy signal conditions too strict, or missing data |
| Data not available | Data not downloaded or timerange not covered |
| Indicators is NaN | Indicator parameters incorrect / incompatible with timeframe |
| Suspected overfitting | Extremely high backtest returns but live losses; use forward testing to verify |
π§ 7. Multi-Process Backtesting Acceleration (--processes)
For multiple pairs or complex strategies, use the --processes parameter to improve backtesting efficiency:
freqtrade backtesting \
--config user_data/config.json \
--strategy MyStrategy \
--processes 4
π§ͺ Generally set to half to all of your CPU cores. For an 8-core CPU, 4-8 processes work well.
π³ 8. Backtesting Commands in Docker Environment
If running Freqtrade in Docker:
docker compose run --rm freqtrade backtesting \
--config /quants/freqtrade/user_data/config.json \
--strategy MyStrategy \
--timeframe 15m \
--timerange 20220101-20230701
Ensure user_data/ is mounted to /quants/freqtrade/user_data/ inside the container.
π 9. Exporting Backtest Results
To save detailed trade information, add:
--export user_data/backtest_result.csv
To export strategy performance results as JSON:
--stats-file user_data/backtest_stats.json
β 10. Recommended Analysis Dimensions
After backtesting, focus on these key metrics:
- Cumulative return (
Total profit): Core indicator - Maximum drawdown (
Drawdown): Risk exposure - Win rate / Profit-loss ratio: Stability assessment
- Average profit per trade: Value per trade
- Profit factor: Whether trading is worthwhile
Also use charting tools for analysis:
freqtrade plot-dataframe --config user_data/config.json --strategy MyStrategy --timerange 20220101-20230101
π Summary
Freqtrade's backtesting system is powerful and flexible, perfect for building a complete strategy research and validation workflow.
| Step | Tool |
|---|---|
| Download historical data | download-data |
| Write strategy class | new-strategy |
| Run backtest | backtesting |
| Graphical display |
backtesting-show / plot-dataframe
|
| Performance acceleration |
--processes multi-process support |
| Containerized usage | Docker commands |


Top comments (0)