Backtesting constitutes a vital component within the realm of Trading system development. Constructing a trading system from scratch necessitates numerous iterations of backtesting to arrive at the most optimized parameters. Additionally, to ensure the system’s stability, one must consistently conduct backtesting on various securities across different timeframes. This process demands considerable time and effort in its entirety. To streamline this procedure, Amibroker has introduced the OLE Automation interface, which allows external applications to access various functionalities of Amibroker, including automated backtesting, optimization, and data import. In this article, we will delve into harnessing this interface to automate the backtesting process in Amibroker.
- A fundamental comprehension of Amibroker and AFL. If you are an absolute beginner, you can start by reading here.
- Access to a basic trading system developed in Amibroker. You can find a list of trading systems here.
- Familiarity with scripting languages like JScript or VB Script.
Steps for Automated Backtesting in Amibroker
Launch Amibroker and navigate to the “Analysis” menu, then select “New Analysis.” Load your AFL formula into the analysis window, ensuring that the backtest settings are appropriately configured.
Proceed to the “File” menu and choose “Save.” Assign a name to this Analysis Project; for instance, let’s name it default.apx.
Open Notepad and paste the following code:
Save this file with the “.JS” extension and then execute it using one of the following options. It is not necessary for Amibroker to be open before executing this file.
Option 1: Simply double-click on the file (Administrator rights are required).
Option 2: Open the Command Prompt, type the name of the JS file, and press “Enter” (Ensure you are in the same directory as the JS file).
Either of these two options will automatically invoke Amibroker’s backtest engine and save the backtest results in a CSV file in the specified path. You will receive a confirmation message upon successful completion. To verify, check for the “Test.CSV” file in the designated location.
You can also open the APX file in Notepad (saved in Step 2) and manually modify the AFL name and code. Moreover, you can automate optimization by adding the line NewA.Run( 4 ) in the JS file. The optimization results can also be saved as a CSV file.
This script provides a fundamental yet significant approach to automating backtests in Amibroker. You can experiment with the JS code to achieve various functionalities. Try implementing a loop to backtest multiple securities across different timeframes or optimize a strategy over different date ranges. Feel free to share any innovative ideas that could enhance the utility of this automation in trading system development.