Back testing a strategy

This tutorial explains how to perform a strategy back test. A back test runs a strategy against historical price data and tells you what the performance would have been during that period. This assumes you have already created and trained a strategy. Back testing is only possible when a strategy is valid and you’ve trained it with a few example trades.

To list your strategies, open the Strategies page by clicking the icon in the page navigation menu on the top right of the page.

Card image cap

Navigate to the Strategies page

The Strategies page will show all of your strategies, and their status. A gray circle denotes that a strategy is still in draft mode and is being edited. After training, the circle will appear orange to denote that the strategy is ready to test.

Card image cap

List of strategies and statuses

Select the strategy you want to test by clicking the glasses icon in the toolbar. If the icon is disabled, it means the strategy is not in a state that can be back tested. This may happen for example if you’ve edited your training set or modified the indicators which the strategy uses. If necessary, train the strategy again so that it is valid.

On clicking the back test button, the back testing page should appear as shown in the screen below.

Card image cap

Back tester results

Performance Summary

The three sections of the page show the profit and loss chart at the top, the holdings below, and a performance summary in the right panel. When viewing on a small screen, the summary panel may be hidden. To toggle the summary panel on a small screen, click the arrow button on the toolbar.

Card image cap

Back tester summary panel

Main summary

  • Blind test: Blind testing means the training & test periods don’t overlap
  • Total profit: Total profit over the selected period
  • Expectancy: The expected return of each trade
  • Profit factor: Sum of wins divided by sum of losses
  • Total trades: Total of executed trades

Trade averages

  • Buys: Total executed buys and percentage won
  • Sells: Total executed sells and percentage won
  • Average win: Average winning trade
  • Average loss: Average losing trade
  • Swap: Accumulated cost of daily swaps
  • Spread cost: Accumulated cost of spread
  • Average holding time: Average time a position is open (chart bars)
  • Average holding: Average size of holding
  • Max holding: Maximum holding at any given time

Risk metrics

  • Worst drawdown: Size of the worst draw down from high to low
  • VAR: 7-period standard 95% Value at Risk (VAR)
  • Volatility: Average period volatility
  • Relative volatility: Relative volatility: coefficient of variation
  • Risk ratio: Sum of floating balances divided by absolute sum of floating balances

These metrics can help determine the risk and reward of a given strategy. Volatility tells you how much net movement to expect in each period. In this example, the chart is a daily chart. So this measure relates to a single day. The VAR tells us that the value at risk over a 7-day period is $937. This means there’s a 5% chance of the strategy losing this amount over an average 7-day time span.

The relative volatility, also know as the coefficient of variation tells us the amount of volatility per unit of average daily return.

The risk ratio shows us how efficient a strategy is in terms of draw down periods. A strategy that spends long periods in deep draw down, even though it is profitable over a period, will have a lower risk ratio than one that spends less time in draw down, or has shallower draw down.

Trade List

To display the list of trades, click the Trade button on the summary panel. This will display a list of all orders that where placed during the run period. The toggle switch at the top will filter out non-executed orders. The screen below shows the resulting trade list.

Card image cap

Reviewing the trade list

Clicking on any row will display that trade on the lower chart. The box will show details of the trade, including entry and exit times, and prices, and the total profit. The stop loss and take profits are shown graphically on the chart. Holding the cursor over either the open or close marker will display more details about that specific trade.

Card image cap

Export trades or positions to CSV file

You can export the trade or the position history to a CSV file for closer inspection. To do this, click the Export button in the summary panel, and choose either Trades or Positions.

Date Range

To set a different date range for the back tester, click the calendar icon in the top tool bar. Set a date range from the panel. Once a date range is set, the tester will refresh and display the new results.

Card image cap

Selecting a date range

If the strategy has been optimized, the selector will show the period over which optimization was carried out. For a back test to be a blind test, the date range should not overlap the training period or the optimization period. That way, the testing uses an independent data set.

Basic Settings

Card image cap

Basic Settings

  • Lots per trade: The trade size in lots
  • Max open positions: Maximum open positions at any time
  • Starting balance: Starting balance in the underlying currency
  • Stop loss percentage: Stop size as percentage of underlying
  • Take profit percentage: Take profit percentage of underlying
  • Close profit: Group take profit percentage
  • Close loss: Group stop loss percentage
  • Test type: Stress test or normal test
  • Profit mode: Currency or pips
  • Order type: Buy side only, sell side only, both

Lots per trade is the size of each trade as multiple of lots. The basic lot size depends on the underlying symbol. For example, for most currencies the lot size is a mini lot. One mini lot has a value of 10,000 units of the base currency. This means one pip movement corresponds to 1 unit of the quote or profit currency.

The stop losses and take profits for individual trades is set as a percentage. The next two settings are the group take profit and group stop loss. This will close all positions if the profit or loss exceeds this percentage. To ignore any setting, leave it as zero.

There are two test types. Normal is the test as the screens above show. The other type is a stress test.

The profit mode can be set to pips or currency. In pips mode, all profit values are displayed as a pip unit of the underlying symbol. The value of a pip depends on the particular symbol. Dividing the profit in currency by the profit in pips will tell you the size of each pip in the profit currency of the symbol. Unlike currency, profit in pips is independent of the lot sizing.

Advanced Settings

Card image cap

Advanced settings

  • Sensitivity: Lower is more conservative, higher is more aggressive
  • Pending order expiry: Expiry time set on pending orders
  • Pending order distance: Distance pending orders are set from bid/ask
  • Average spread: Spread between bid/ask in pips
  • Maximum leverage: Highest leverage allowed
  • Long swap rate: Overnight swap cost for long position in points
  • Short swap rate: Overnight swap cost for short position in points
  • Order placement: Order type
  • Close on trend reverse: Close opposing trades on new signal
  • Randomized testing: Randomize market conditions

The sensitivity controls how aggressive the strategy will be. A lower number will generally reduce the number of trades, while a higher number will increase the number of trades.

The pending order expiry will set the time limit for expiring pending orders. The pending order distance sets the range at which a stop or limit order is set from the current bid or ask price. For example, with a buy limit order, if the distance is set at 1%, the entry price for the buy limit is set at 1% below the current ask price.

The average spread is the average range between the bid and the ask price. This should be set in pips. By convention, the swap values are set in points (one tenth of one pip). These are the swap fees added when a position is rolled over to the next day.

The maximum leverage limits how much free margin you need to open a new position and to hold open your existing positions. High leverage means you need a lower balance to control larger trade volumes. The back tester will stop opening new trades from the any point at which the margin limit is reached.

Order placement sets the type of order. Market means immediate execution at market price. Stop orders and limit orders place orders with a time limit, and at a distance from the current bid and ask price. Sell stop orders are placed below market while buy stop orders are placed above market. Sell limit orders are placed above market while buy limit orders are placed below market.

If Close on trend reverse is switched on, the strategy will close any opposing trades when a new signal is received. For example, when a new buy signal is received, the strategy will close short positions. When a new sell signal is received, the strategy will close any long positions. This switch can help manage no hedging rules.

Randomized testing sets whether back testing will randomize market conditions. Randomized testing may produce different results each time the back tester runs.

Inputs

The third tab on the panel, Inputs will show which indicators the strategy uses.

Card image cap

Strategy inputs

Risk Disclosure: Information given on this website is for general purposes only and should not be construed as investment advice. Certain instruments shown here are complex and may come with a high risk of losing money rapidly due to leverage. You should consider whether you understand how these instruments work and whether you can afford to take the high risk of losing your money. Market data displayed is indicative and is not a solicitation to buy or sell.