Skip to main content

Running Backtests

Backtesting is your secret weapon for developing and validating trading strategies. It lets you see how your strategies would have performed on historical data before risking any real money. By running backtests, you can spot the strengths and weaknesses in your strategies and make informed tweaks.

Preliminary Considerations​

To avoid any interference with your real trading data, set up a second Gunbot folder specifically for running tests. This way, your real trading activities won't get mixed up with data from backtesting.

Steps to Create a Second Gunbot Folder:

  1. Copy your entire Gunbot folder to a new directory.
  2. Open the config.js file in a text editor.
  3. In the GUI section, change the port number:
    "PORT": 3000, --> Change to a different port number, for example, 5050

Tips for Effective Backtesting​

  • Test a Single Pair at a Time: Running multiple pairs in a single backtesting instance is not supported. Split instances when you want to run tests in parallel.
  • Separate Instances: Keep your backtesting instance separate from your live trading instance.
  • Clear JSON State Files: Before starting a new test for the same pair, clear the JSON state files from previous runs.
  • Custom strategies: To use multiple timeframe candles during backtesting, enable the MULTI_COMP override.
  • AutoConfig: Autoconfig jobs that use internal data, like manageOverrides jobs, are fully supported for backtests. Before the backtesting run starts it creates a 'fake' schedule based on your job schedule settings, so that jobs would execute in the same candle as they would in a real trading situation.
  • Bring some patience: Because this mode really runs ALL gunbot code it would normally do for real trading, backtesting runs can get time consuming.

Setting Up Backtesting in Gunbot​

Enable Backfester​

  1. Navigate to http://localhost:3000/setup#advanced and enable the backfester feature. Gunbot backfester feature activation interface

Configure Starting Balances​

  1. In the same dialog, configure the starting balances for your backtests. Select the exchange, base currency, and enter the starting balance. Gunbot backtesting balance configuration screen

Steps to run Backtests​

Select a Trading Pair​

  1. On the trading settings page, select the trading pair you want to test.

Configure Start and End Times​

  1. Set the start and end timestamps for the test runs. Gunbot backtesting start and end times configuration screen

Methodology​

Gunbot runs backtests using the exact same strategy and core code as it does for real trading. This means the results are as close to real as it gets, minus actual balance changes and live market data fetching.

Without Deep Testing​

  • Gunbot collects historical candle data for the selected timespan.
  • Strategies iterate through all candles for the chosen candle timeframe, one iteration per candle.

With Deep Testing​

  • Gunbot collects the public trading history for the selected timespan.
  • It builds candles from the trading history and runs the strategy code multiple times within a single candle if multiple trades occurred that caused a price change within a candle.

Viewing and Interpreting Results​

While the test is running, you can view the trading chart and dashboard in real-time, similar to watching a normal Gunbot session on fast-forward. Each run generates a JSON report file stored in the backtestingReports folder. These files are great for sharing with the backtesting community on Gunbot's Backtesting Archive.