Skip to content

How to Backtest a cBot

In this article and its corresponding video, we would like to discuss how you can backtest a cBot. You will learn where you can access backtesting, how you can configure backtesting settings, and how you can interpret the results of backtesting.

Backtesting in cTrader

cBots are fully customisable trading robots that you can configure to perform various trading actions when encountering certain market movements and events (e.g., MACD crossovers).

However, when coding a cBot, it may be challenging to get everything right on the first try. In most cases, you would want to refine a cBot before letting it trade on your behalf.

This is where backtesting comes in. Think of backtesting as a playground in which you can let cBots trade on historical market data without risking anything tangible. As such, backtesting is invaluable for evaluating whether cBots can achieve their intended results without risking any real funds in your trading account.

We highly recommend conducting thorough backtesting for any cBots that you have created yourself or have acquired through other channels.

How to Access Backtesting in cTrader

To access backtesting, first, select an existing instance of the cBot you would like to evaluate. Just below the topmost bar in the UI (the one containing the 'Back' button), you should see several tabs with the first tab containing the trading chart on which the currently chosen instance is operating.

The 'Backtesting' tab should be to its immediate right. Click on it to switch to the backtesting area.

Image title

After opening this tab, you should see the following interface.

Image title

How to Set the Period for Backtesting

As stated previously, backtesting allows you to run a cBot instance on historical market data. You have several options for defining the exact period that the backtesting process should cover.

Use the Slider

The calendar slider is located closer to the top of the 'Backtesting' tab.

Image title

Drag both grey 'points' across the slider to specify the data range for subsequent backtesting. In the screenshot above, we have dragged one of the 'points' to cover a period that is approximately equal to two years.

Use the Menus

You can also use the calendar drop-down menus to the left and the right of the slider to select a precise date range.

Image title

To make sure that our backtesting period is exactly two years in length, we can open the menu to the left to select November 30th 2020 as the new start date.

How to Configure Backtesting Settings

Before performing a backtest, click on the 'cog' icon just to the left of the leftmost calendar menu. You should see the following settings.

Image title

With this section open, perform the following actions.

  • In the 'Starting Capital' field, specify the initial funds that your cBot will start out with.
  • Open the 'Commission' menu and choose (or type) the commission that your cBot will pay after trading a million units in volume.
  • In the 'Data' menu, set up the source of historical data for backtesting. Generally speaking, receiving m1 data from the server is a good compromise between accuracy and the resource-intensiveness of backtesting. Note that you can also upload custom data from a locally stored .CSV file.
  • Choose between fixed or random spreads in the 'Spreads' sub-section. Click on 'Live' to match the fixed spread (if it is chosen) to the current symbol spread.

Refer to the this tutorial to learn more about backtesting settings and how they can affect the results of backtesting.

How to Choose Between Backtesting Modes

You may choose to see the results of backtesting (e.g., the positions opened by your cBot) as they occur. This functionality is particularly useful for detecting certain events and conditions under which your cBot does not behave as expected.

To access it, enable the 'Visual Mode' flag just below and to the left of the calendar slider. In the 'Speed' menu, select the speed with which the chosen trading chart will be played back. Note that you can always change the playback speed while backtesting occurs.

Image title

Alternatively, leave the 'Visual Mode' flag disabled. Instead of watching backtesting in real-time, you will receive a one-time report containing its results at its conclusion.

For now, we will keep the visual mode functionality disabled.

How to Launch Backtesting

To perform a backtest with the given settings and in the chosen mode, click on the 'Play' button to the right of the rightmost calendar menu.

cTrader will start loading the required historical data. This process may take several minutes depending on the period you have chosen and the hardware on which you are running cTrader.

In our case, the process is relatively quick as we have only requested information for two years. When backtesting occurs, you will see the bar to the right of the 'Visual Mode' flag gradually move from left to right.

When it moves fully to the right, the backtesting process will conclude.

How to See the Results of Backtesting

There are a number of ways you can use to judge the results of backtesting. After backtesting is concluded, the number at the centre-top of the trading chart will summarise the total net profit generated by your cBot.

Image title

In our case, the cBot has earned a staggering net profit of 503%.

Another way to evaluate the performance of your cBot is to switch to the 'Equity' tab in the trade panel just below the trade chart. You will see a chart with the total number of trades your cBot has made on the X-axis and funds on the Y-axis.

The yellow line will track your cBot balance while the grey line will track its equity.

Image title

We can see that our cBot was doing well throughout backtesting but there may be some cases that we may want to correct before giving it access to real funds.

Last but not least, the 'Trade Statistics' tab will display cumulative statistics about all trading actions performed by your cBot.

Image title

We can see that our total returns were great. The robot made a total of 271 winning trades and a huge portion (33,009.55) of the total returns were generated by just one trade! The cBot clearly has some potential for making risky plays.

Summary

Backtesting is a great way to ensure that your cBot performs as expected. Using detailed statistics and the equity chart, you can pinpoint the price moments when the robot you are testing was making the right (or the wrong) moves. Backtesting is also fully customisable, allowing you to train your bots in wildly different conditions.

Subscribe to our YouTube channel