Backtesting Strategy

From FxCodeBaseWiki
Jump to: navigation, search

What is Backtesting?

Backtesting is an execution of a strategy or a signal on historical data. You “pretend” that historical prices are happening “right now” and see how the strategy would have worked if the market had been as such. To backtest, you have to choose the strategy you want to look at and the historical range you want to test your strategy on. Usually it's interesting to backtest a strategy over a long period of time, such as months and sometimes years.

For example, below is the equity and balance curves of standard MA_ADVISOR strategy executed over 2010 history of EUR/CHF (3.5 million of ticks, 8 ticks per minute), applied on 15-minute frame, with 15/55 short/long MA parameters, with no stops and limits, shown on 1-hour chart. You can see all "classic" Moving Average-based strategies problems: it tends to loose on flat market and works well only when the trend is well built.

Backtest1.png

Backtesting is very similar to strategy debugging. You can see exactly the same data (tick log, statistics, charts). The only difference is that you execute the strategy without any debugging and are only to see the final result. Because debugging features are not used, the backtest runs as fast as the strategy can be executed. It takes less than a minute for a well-written strategy to be backtested over the whole year.

Backtest Configuration

To backtest a strategy, use the Check Performance/Backtest command (Project menu) of the Integrated Lua Editor/Debugger. The list of indicators/strategies will be shown. Please note that both user and standard strategies can be backtested. After you select the strategy, its parameters will be shown.

Configuring backtesting is the same as configuring debugging session parameters, so please read the entire Debugging Strategy article for details. A few notes:

  • It is strongly recommended that you use 1-minute data to simulate the market during backtesting.
  • The SDK does not contain the whole year price data files. Marketscope also cannot be used for saving 1-minute data longer than 1 week. To get the price data, you can download it via SDK using the quotes manager.
  • Do not forget to allow trading in your strategy. Most strategies won’t trade unless you explicitly allow it.

Running Backtester

After you hit OK in the strategy parameters, backtesting will begin. You can see the progress in the number of ticks simulated and the time already elapsed. A 1-minute year history produces from 3.5M (5-day trading week) to 5M (7-day trading week) ticks. A well-written strategy must be executed in 1 minute or less on 3GHz processor. The number of cores does not matter, the backtester uses only one core.

If it takes too long, you can always break the backtesting process and choose a shorter time period.

If you are a developer and it is your strategy that works so long in the backtest mode, please read Strategy Optimization that will help you improve the strategy performance.

Backtest Result

When backtesting is finished, the following data is shown:

  • The time spent for backtesting, the number of ticks simulated, the performance of the strategy (ticks per second) (shown on the Output tab).
  • A complete tick log of backtesting (shown on the Streams tab)
  • The overall trading performance (shown on the Statistics tab)
  • The strategy results displayed as a chart (shown on the Chart tab)

To learn how to read and use data shown on these tabs, please refer to Debugging Strategy. Table-related and optimizer-related tabs are empty.

Special Notice About Backtesting Reports

Hypothetical or simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-overcompensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This Article in Other Languages

Language: English  • español • français • русский • 中文 • 中文(繁體)‎