DEV Community

Cover image for Chapter 4: "How to Test Strategies Reliably? Freqtrade Backtesting Command Full Guide"
itrade icu
itrade icu

Posted on • Originally published at itrade.icu

Chapter 4: "How to Test Strategies Reliably? Freqtrade Backtesting Command Full Guide"

πŸ“˜ 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
Enter fullscreen mode Exit fullscreen mode

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:

  1. βœ… Historical data for the corresponding timeframe has been downloaded:
freqtrade download-data --timeframes 15m --timerange 20220101-20230701
Enter fullscreen mode Exit fullscreen mode
  1. βœ… Strategy file is placed in user_data/strategies/ directory with correct class name.
  2. βœ… config.json settings are correct, including:
    • Correct trading pairs
    • Correct exchange settings
    • stake_currency set 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
Enter fullscreen mode Exit fullscreen mode

πŸ“ 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
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To export strategy performance results as JSON:

--stats-file user_data/backtest_stats.json
Enter fullscreen mode Exit fullscreen mode

βœ… 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
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ 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)