Sweep Parameters in Backtest
This tutorial will guide you through the essential steps to sweep parameters in backtest.
1. Sign In to Launch BotiTrader
- Open the software after installation.
- Enter your registered email and password, then click "Sign In".
- Once signed in, you will see the main interface.
2. Select a Strategy and Set the Historical Data in the Backtest Window
- In the Main window, at the top of the charting window, click "Create Trading Bot".
- The Backtest window will appear.
- On the left side of the Backtest window, click to select a strategy from the Strategy List.
- Below the strategy list, you will see a "Historical Data" section:
a. An existing historical dataset should have been loaded automatically.
b. If you have already connected your broker account, you can change the symbol or timeframe to download the latest data.
c. You can always adjust the slider to modify the date range for the backtest.
3. Set Up the Strategy Parameters
- At the top center of the Backtest window, click on the Strategy Parameters tab. A table will appear, listing all the strategy parameters.
- In the first column of the table, you will see the parameter categories. At the top, you'll find a category called Algorithmic Parameters, which are custom parameters extracted directly from the strategy code. To understand these better, switch to the Strategy Code Editor tab, where explanations for these parameters are usually provided at the top of the code.
- In the first column of the table, you’ll also see 6 built-in parameter categories: Order Type Parameters, Order Size Parameters, Order Stoploss Parameters, Order Takeprofit Parameters, Intraday Trading Parameters, and Backtest Parameters. These parameters apply to all strategies. Hover over the second column to view the tooltip for each parameter, which provides a detailed explanation. Alternatively, you can find the definition, value range, and examples for each parameter in the table below.
- In the third column of the parameter table, you can set the value of each parameter.
- In the fourth column of the parameter table, you can enable the parameters that you want to sweep. This feature supports all numerical parameters. Once you enable a parameter, input values in the fifth, sixth, and seventh columns to set the minimum value, maximum value and step size. For example, if you set
min_value=10
,max_value=30
, andstep_size=5
, the backtest will run 5 different values for this parameter: 10, 15, 20, 25, and 30.
4. Run Backtest
- In the Backtest window, at the bottom of the left panel, click "Start Backtest" to run a backtest. A backtest simulates your selected strategy using historical data, allowing you to evaluate its performance over the chosen date range. For the parameters you didn't enable for sweeping, the default value in column 3 will be used. For the parameters you enabled for sweeping, the backtest will run for each combination of the swept parameters. For example, if you enabled parameter_1 with
min_value=10
,max_value=30
, andstep_size=5
, and enabled parameter_2 withmin_value=20
,max_value=50
, andstep_size=10
, you have 5 different values for parameter_1 and 4 different values for parameter_2, so the backtest will be run for a total of 5x4=20 different combinations. - Once the backtest is complete, click the Backtest Results tab at the top of the backtest window to view the result table.
- For each parameter combination, you'll see one row in the backtest results table that lists all the metrics of the performance. Below is a table explaining each column in the results table.
-
You can also click on each row in the backtest results table, or click "View Historical Results" at the top of the Backtest window to view the details of the performance, including:
- A trade list table showing detailed information for each trade (appears at the bottom left of the screen).
- A portfolio chart comparing the strategy's performance with the buy-and-hold performance (appears at the bottom right of the screen).
- A statistics table (appears on the right of the screen).
-
You can also click "Show Historical Trades on Chart" at the top of the Backtest window to display all trades on the charts. Winning trades are marked with green lines, and losing trades with red lines to indicate the entry and exit points. Please note that if the total number of trades is too high (for example, more than 100 trades), the plot may become slow and impact the computer’s performance. Therefore, it is not recommended to plot trades in such cases.
5. Find a Parameter Combination for the Best Performance
To find a parameter combination for the best performance, consider the following tips based on the backtest results:
- Maximize the Final Portfolio Value ($): ensure that your strategy generates as much more profits as possible. This is key to long-term success.
- Improve the Win Rate (%) and Profit Factor: Aim for a higher Win Rate and Profit Factor to ensure your strategy is profitable. However, it’s important to balance these with realistic drawdowns to avoid taking on excessive risk.
- Control Max Drawdowns ($): Maximize the Sharpe Ratio and minimize the Max Drawdown. If you see large drawdowns, consider adjusting stop-loss strategies or reducing position sizes.
- Maximize the Sharpe Ratio: The Sharpe Ratio is crucial for evaluating your strategy’s risk-adjusted return. To improve it, aim to increase the return of the strategy while minimizing risk. If your Sharpe Ratio is low, consider refining the strategy to reduce volatility, such as tightening stop-loss settings or using less aggressive position sizing.
6. Next Steps
If the backtest results do not meet your expectations, you have several options for moving forward:
- Switch to the Strategy Parameters tab and adjust the parameter table to sweep different combinations of parameters.
- Change the symbol or time frame of the historical data in the left panel of the Backtest window.
- Click "AI Automation Assistant" at the top of the Backtest window and use the AI automation to modify the strategy code.
If you're satisfied with the backtest results, select the desired row in the backtest results table. Then, click "Create Trading Bot" at the top of the Backtest window to create a new trading bot.