Introduction to Backtesting
Backtesting allow you to test trading strategies across a range of historical dates. Tests can be made against specific symbols or you can use position sizing rules to simulate multi-holding portfolios. You can run and compare multiple Tests for the same Strategy to quickly see how criteria or parameter changes affect the results.
A Strategy consists of trade criteria, stops, targets, and position sizing rules. For example, a Strategy may consist of the following elements:
You could then run multiple Tests with perhaps different MA Periods and easily compare the results to see which is more profitable.
Click 'Customize Criteria and Run Test' to open or close the criteria customization panel.
In the customization panel you can run tests and make copies. If you are viewing one of your existing Tests click 'Run Test' to run another test under the Strategy or 'Copy to New Strategy' to build an additional Strategy based on the test currently on display. And if the Strategy on display is a site sample or from another user click 'Apply Changes & Save to My Id' to save it to your account.
Once your Test has completed running you can view summary results in the Grid below and detailed information on the other tabs on this page.
Include and Exclude Symbol Groups
Symbol Groups are the universe of symbols to search. Various different methods of selection are available including Exchanges, Sectors, Watch Lists, Specific Symbols, etc.
You can also choose to Exclude specific symbols or groups of symbols. If there is a recurring group of stocks you wish to exclude it may be better to set these up in a watch list and exclude the list.
Buy, Sell, Short Sell, and Cover Short criteria allow you to set separate rules for entering and exiting trades. As a minimum, you must enter either at least one Buy or at least one Short Sell criteria. You do not need to enter Sell or Cover Short criteria if all trades are to be closed by stops.
The Buy and Short Sell criteria will be evaluated each day of the Test to determine new positions, subject to the available Equity, Position Sizing, and Maximum Position settings. The Sell and Cover Short criteria will be evaluated each day of the Test for existing positions to see whether they should be closed.
In general, each filter criteria consists of a comparison between one fundamental or technical analysis value and another fundamental or technical analysis value, or a specific value.
You may have the following criteria:
This simple criteria will return all stocks where the close price is greater than or equal to 10 dollars.
This criteria is not very selective so we could include an additional comparison as follows:
Now the criteria will return all stocks where the close price is greater than or equal to 10 dollars and the close price has crossed above the 200 day moving average.
compares the item on the left-hand side of the criteria with the item on the right-hand side. The right-hand item can be a specific value.
The criteria will pass if the left is exactly equal to the right.
Be careful with 'Equal to' and technical values as there may be rounding issues. For example, rather than having a criteria of 'Beta equal to 1', it may be better to use two criteria of 'Beta greater than or equal to .99' and 'Beta Less than or equal to 1.01'.
The criteria will pass if the left is less than the right.
Less than or equal to
The criteria will pass if the left is less than or exactly equal to the right.
The criteria will pass if the left is greater than the right.
Greater than or equal to
The criteria will pass if the left is greater than or exactly equal to the right.
The criteria will pass if the left is greater than the right, but on the previous bar the left had been less than the right.
In last bars
You can also specify a number of bars to check in which case the criteria will pass if it is true on any one of the bars.
The criteria will pass if the left is less the right, but on the previous bar the left had been greater than the right.
Has been above
The criteria will pass if the left has been greater than the right on each of the number bars specified.
Has been below
The criteria will pass if the left has been less than the right on each of the number bars specified.
compares the item on the left-hand side of the criteria for the number of bars specified.
The critieria will pass if the latest value is greater than all the values for the previous bars.
The critieria will pass if the latest value is lower than all the values for the previous bars.
The critieria will pass if each value is progressively higher than the value for the previous bar.
The critieria will pass if each value is progressively lower than the value for the previous bar.
Occurred on latest or in previous
is used for date-based criteria and compares the item on the left-hand side of the criteria for the latest bar and the number of previous bars specified.
For example, to include stocks which have traded on the latest trading day or on either of the two previous trading days you could specify 'Trade Date occured on latest or in previous 2 bars'. Stocks which have not traded for 3 days would be ignored.
is used for text-based criteria and compares the item on the left-hand side of the criteria to see whether a value has been set.
For example, you could specify 'Sector present' to select stocks which have been assigned to Sectors.
For example, you could specify 'Sector not present' to select stocks which have not been assigned to Sectors.
is used for pattern-based criteria.
For example, you may have created a Stock Pattern with various criteria and called it 'My Pattern'. In the screen criteria you would then specify a criteria of 'My Pattern true' and the criteria in the pattern would be evaluated in addition to the other criteria in the screen.
You can enter separate criteria for Buy, Sell, Short Sell, or Cover Short. The Buy criteria will show first by default. Click the links next to 'Show criteria for' to access the others.
You must enter at least one criteria under either Buy or Short Sell to get any results.
Enter as many criteria pairs as you need to narrow down your entries and exits. To enter a new criteria on the criteria builder first click 'New Criteria', choose your required Fundamental / Technical Indicator Item, then select the Condition to apply, and finally choose a right-hand Fundamental / Technical Indicator Item or Specific Value to compare to.
Click 'Run Test...' to save all of your changes and display the new results.
To adjust the settings of an existing left or right criteria Item just click on the Item to display the details popup. For example, to change an Item containing EMA(50) to EMA(100), first click on EMA(50), change the Period to 100, close the popup, and click 'Run Test...' to apply.
Is the amount of the cash in the portfolio at the beginning of the Test.
Choose an amount which is appropriate according to your position sizing and maximum positions settings. If the amount is too low the testing engine may not have sufficient cash to enter positions even though a Buy/Short signal is found.
Five position sizing algorithms are available:
Long and Short Amounts
Long and short positions can have different settings. Eg 1000 shares for Long and 500 for Short. For Shorts, if no amount is specified the Long amount is used.
% of Current Equity to Risk
This position sizing choice allows you to control position sizes depending on the performance of the portfolio and the volatility of each stock.
For example, you may choose to risk 2% of current equity on each trade with a stop loss of 3 ATRs:
If the Current Equity is 100,000 then the amount to be risked is 2,000. In other words, the stop should be hit if you lose 2,000 or more on the trade. If the stock has a current ATR of 0.50 you calculate the number of shares to trade as follows:
Shares = 2,000 / (3 * 0.50) = 1,333.33 = 1,330 (rounded to nearest 10)
Working backwards, if the stop of 3 * 0.50 is hit then a loss of 1,995 will result. (Slightly different from 2,000 due to the share rounding.)
Maximum Open Positions
Is the maximum number of open positions at any one time during the test. If Buy/Short signals are found but there are insufficient position slots available, the signals will be ignored.
Maximum New Positions in One Day
Is the maximum number of new positions that can be entered on one day of the test. If Buy/Short signals are found but there are insufficient new position slots available, the signals will be ignored.
Often there will be more potential trades available for a particular day than there are position slots available. (Based on the Maximum Open Positions and Maximum New Positions in One Day settings.) Choose how you would like to prioritize stocks in such a situation. This is similar to running a screen and then sorting by one of the columns.
You can choose to enter trades at the close of the day when the signal is found or at the open of the following day. Please note that this option applies to Buy and Short. Stops and Targets have their own options.
You can choose to exit trades at the close of the day when the signal is found or at the open of the following day. Please note that this option applies to Sell and Cover. Stops and Targets have their own options.
Existing Position can be Switched
Usually, if a stock is already in a position then it can only be closed by stops, targets, or sell or cover short criteria.
However, you may have a strategy where you want a symbol to be in a trade all the time. For example you could have a strategy which contains only Buy and Short Sell criteria. Once a symbol is in a position then, depending on the criteria, it would continually close the existing position and enter a new one in the opposite direction (E.g. long to short or short to long). In this case you would need to set this option.
Position Size Rounding
Certain position sizing choices may result in part quantities. Choose how you wish to round the positions.
Stops and Targets
Stops can be set based on percentages or ATR movements. Separate settings are available for Long and Short positions. You can also specify the timing of the exit and therefore the price to be used.
Trailing Stop Loss
Trailing Stops can be set based on percentages or ATR movements. Separate settings are available for Long and Short positions. You can also specify the timing of the exit and therefore the price to be used.
Trailing Stop Loss uses Close or High Price
When calculating the trailing loss you can choose whether it should use the best close price achieved during the trade or the best high price (low for shorts).
Target Stops can be set based on percentages or ATR movements. Separate settings are available for Long and Short positions. You can also specify the timing of the exit and therefore the price to be used.
ATR Stops Period
If you set ATR stops, the period for the average true range calculation is also required.
Time Stops will cause a position to be closed after the specified number of days. Separate settings are available for Long and Short positions. You can also specify the timing of the exit and therefore the price to be used.
Entry Costs %
Enter percentage adjustments to account for entry costs, ie brokerage. For example, an Entry Costs % of 0.1 on a trade which has a value of 10,000usd will result in an additional 10usd cost.
Exit Costs %
Enter percentage adjustments to account for exit costs, ie brokerage. For example, an Exit Costs % of 0.1 on a trade which has a value of 10,000usd will result in an additional 10usd cost.
Depending on your broker and method of trading, you may not always get the strategy prices. You can specify a Slippage % to reflect this.
For example, a Slippage % of 0.2 will mean that all entry and exit prices are adjusted, for example, a Buy price of 25usd will become 25.05usd. All prices are affected including stops.
Is the ranges of dates over which the test should run. You can specify fixed dates or a number of trading days.
Click 'Run Test...' when you have completed all changes.
The length of time the test takes to run depends on the complexity and test period.
Customize Grid Columns
Click 'Customize Grid Columns' to open or close the Grid customization panel.
To add a new Column click 'Add New Column'. For example, you may wish to add Volume to the Grid. First click 'Add New Column', select Volume, close the details popup, and then 'Apply...' and the Grid will be extended to show Volume.
Use the Up and Down buttons to re-arrange the Column order within the Grid.
To adjust the settings of an existing Column just click on the Column to display the details popup. For example, to change a Column containing EMA(50) to EMA(100), first click on EMA(50), change the Period to 100 and click an 'Apply...' button to save.
The Number of static Columns setting determines how the Grid is laid out and is especially useful to prevent horizontal scrolling on devices with narrow screen width.
This setting is held at the device level and applies to all Grids across all views.
Moving Average Cross
This example Strategy Buys when an instrument moves above the Exponential Moving Average and Sells when the instrument moves back below the EMA.
The rules are:
Click 'Apply Changes & Run Test' under the 'Customize Criteria...' panel to adapt to your preferences and run tests.