Optimizing Strategy Parameters using SDK 2.0 (Step by Step Instruction)
Contents
Introduction
This article provides step-by-step instructions on how to backtest and optimize strategy parameters using Indicore SDK 2.0.
The article uses the Marketscope standard MA_Advisor strategy as an example but any other standard or custom strategy can be backtested/optimized in the same way.
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 in the event that any account achieves profit or losses that are similar to those shown.
Prepare Environment
Indicore SDK
Download and install the latest version of Indicore SDK. Use the default installation folder.
Use the link below to download the latest version:
Download Price Data
You can download the files with prices from CodeBase Price Archive or use data from the quotes manager server.
Price Archive
To be able to use data from CodeBase Price Archive, first, download and install 7-Zip archiver. The application is used for unpacking the price data which can be downloaded from http://fxcodebase.com.
To download the latest version, use the links below:
Next, download and install the price data:
- Open the CodeBase Price Archive article and save the data for the instruments you are going to optimize.
- Save the strategy in a folder on your computer.
- Open that folder and locate the downloaded file. For the 2010 history of EUR/USD, the file is named as EURUSD-2010.7z. Right-click on the file.
- In the pop-up menu, point to 7-zip and click Extract Files:
- The 7zip archiver opens. In the archiver window, select
C:\Gehtsoft\IndicoreSDK\data
to extract the file and click OK.
Quotes Manager
You can use the quotes manager server to download the 1-minute quote data for the chosen instrument in the chosen period. The data is downloaded fast. Loading of the entire year of 1-minute data for an instrument (approx 300K candles) usually takes less than 30 seconds.
To download the data from the quotes manager:
- Run the Integrated Lua EditorDebugger application from Indicore SDK application group in the Start menu.
- On the Tools menu, choose Load Quotes:
- The Load Quotes dialog box appears. Choose the instrument and the year for which you want to download the price data and click on OK.
- Wait a bit while the data loads:
That's all. Now you can use the downloaded data for the chosen instrument and the period for optimization.
Prepare To Run the Strategy in the Debugger
Using Lua Strategy Debugger to Install a Strategy
Since Apr, 26 2011, with the Indicore SDK 2.0 release (beta update 2) the new command: File->Install Custom Strategy is introduced. Now you can save the strategy in any folder, and use this command to install the strategy into the proper place.
After the SDK 2.0 has been installed, no strategies exists. You must create or install a strategy before debugging:
Click the Install Custom Strategy in File menu of debugger:
The file open dialog appears. Choose the Lua file with the strategy that you want to debug, backtest or optimize and click on Open:
That's all. The strategy is installed. Now you can choose any operation (e.g. debug, test or optimize) and the strategy that installed in the step above appears in the choice and can be chosen:
Install a Strategy Manually
Alternatively, you can copy a file into the proper place.
Copy the strategy you want to optimize to the following folder: C:\Gehtsoft\IndicoreSDK\strategies
. You are optimizing the standard Marketscope MA_Advisor strategy, so:
- Open one of the following folders in Explorer:
C:\Gehtsoft\IndicoreSDK\strategies\standard
orC:\Program Files\Candleworks\FXTS2.Dev\Strategies\Standard\
. - Locate the following files:
ma_advisor.lua
andma_advisor.lua.rc
. - Copy both files.
- Open the following folder in the Explorer:
C:\Gehtsoft\IndicoreSDK\strategies
. - Paste the files.
Copying Fxcodebase Strategies
If you want to backtest or optimize a strategy from http://fxcodebase.com:
- Save the strategy to
C:\Gehtsoft\IndicoreSDK\strategies
. - If the strategy requires one or more custom indicators, save all of them to
C:\Gehtsoft\IndicoreSDK\indicators
.
Run the Debugger
Run the Integrated Lua EditorDebugger application from the Indicore SDK application group in the Start menu.
Backtest Strategy
Why Backtest First?
First of all, you should check whether the strategy is fast enough to be optimized successfully. It also gives you an idea of how effective the optimization of this particular strategy is.
Configure Backtesting
- In the debugger, click Tools->Check Performance/Backtest. The list of strategies appears.
- Select the strategy that you want to backtest (MA_ADVISOR in our case) and then click on OK. The backtest configuration dialog box appears:
- First, specify simulation parameters. Your strategy works only on one instrument, so you configure the First Instrument Price Source parameter only. Place the cursor in the parameter value field and click on the ellipsis (
...
) button. You see the Choose Price Source dialog box: Click either File and select the previously saved price file or click on Quotes Manager to use the previously downloaded data from the quotes manager. And then, click on OK.
- Leave the rest of the simulation parameters at their default values. The default parameter set corresponds to a non-hedging UK Mini account.
- To simulate a hedging account, set Are closing orders allowed? and Is hedging allowed? to Yes.
- To simulate a FIFO (US) account, set Are closing orders allowed? and Is hedging allowed? to No.
- To simulate a Micro account, set MMR to 1 and Lot Size to 100.
Configure Strategy Parameters
After you have specified the simulation parameters, you need to configure the strategy parameters. To do so,
- In the Parameters dialog, locate the Indicator Parameters(Price) group and set Timeframe to H1 (1 hour). Strategies based on the moving average work well on this time frame.
- Then locate the Indicator Parameters(Trading Parameters) group and set Allow trading to Yes. Otherwise, the strategy does not trade.
Can You Backtest on 1-Minute Timeframe Anyway?
Yes, you can. However, in this case you need to configure the chart view. By default, it shows 1-hour prices. For a 1-minute strategy, such chart may not be very convenient since each bar has many trades. To configure the chart view, in the Parameters dialog, locate the Chart Parameters group and set Timeframe to m1 (1 minute).
Start Backtesting
To start backtesting, configure all of the parameters as discussed above and click on OK.
Run Backtest
Once the backtesting starts, one or more prompts for loading the historical data may be shown. These prompts appear when the strategy requests the trade history (a 1-hour history, in your case).
If you are backtesting on H1 or smaller time frame on the entire year range, simply click on Empty History. In this case, the backtester collects the history data using simulated ticks.
In event that a bigger time frame (days, weeks, etc.) is used, clicking on Empty History leads to a situation where the strategy starts trading late, after enough data is collected. In this case, use data from the quotes manager server. Just choose the Quotes Manager in the dialog box, click on OK and the necessary data loads.
Read the Backtest Results
Output
First, take a look at the information on the Output tab of the debugger.
- There must be no errors since the last start.
- There must be no debug output of the strategy, it can significantly slow down the optimization.
- Check the performance report. For 3.0GHz processor, the backtest must take no longer than 10 seconds. Otherwise, the optimization may take too much time. If it takes longer than 10 seconds, the strategy performance is optimized first. Contact the strategy developer. If you are the developer, please read the following article: Strategy Optimization.
Overall Statistics
Then you can check the Statistics tab for the overall performance of the strategy.
The strategy earned $576 during a year but during that year there was up to $2082.60 loss. Note the maximum fall of the balance. This change in the balance is generally understood to be unimpressive.
Chart
Finally, you can check the Chart tab to view the equity and balance curves:
The equity curve goes up and down, so the chances for the strategy to be profitable or non-profitable are the same.
Decision
As you can see, the strategy is fast enough to be used in the optimizer and the optimization is really required.
Optimize Strategy Parameters
Configure Optimizer
- In the debugger, click on Tools->Optimize. The list of strategies appears.
- Select the strategy that you want to optimize (MA_ADVISOR in our case) and click on OK. The Optimization configuration appears.
- Configure the simulation parameters the same way that you configured these parameters for backtesting.
- Set the default optimization parameter to Profit Factor.
Note: To learn what the Method parameter is, refer to Optimizing Strategy Parameters.
Note: If a time critical application is being executed on your PC (for example, the Trading Station on a real account), please specify a smaller value in the Agents number parameter. This slows down the optimization process a bit but allows for some processor time required for other applications.
Note: Quad core CPU (i5, i7) is strongly recommended for optimizing strategies.
Configure Strategy Parameters
- First, decide which parameters are to be optimized. In your case, there are two parameters to optimize: the number of periods for the fast moving average and the number of periods for the slow moving average. Different sources suggest that the parameter value for the fast moving average should be in the range of 3 to 12, and that the slow moving average should be in the range of 13 to 30. You can now see what functions best for the EUR/USD in 2010.
- Please note that parameters which can be optimized, have a plus sign on the left side. Click on that sign to set the minimum and maximum values to search for optimal parameters.
- Remember to set the Timeframe to H1 (1 hour) and Allow Trading to Yes.
Run the Optimizer
The optimizer may ask for historical data the same way that it does for backtesting (#Run Backtest). Click on Empty History or select the historical data exactly as you did for backtesting.
The time spent on optimization depends on:
- How fast the strategy is;
- How many parameters are chosen for optimization;
- How wide the range of the value to be optimized is.
The optimization with the parameters that you specified took about 1 minute on single Intel Core i7 3GHz CPU (8 Cores).
Read the Optimization Results
Output
The output shows the internal optimization parameters and the number of the parameter set which has shown the best result.
Result Table
The optimization result table shows all tested parameter sets and the statistic for each of the sets. The best set is highlighted in green. The sets which are not profitable at all, are highlighted in red.
The Results Graph
The result graph shows the optimization results. You can choose any two of the parameters chosen for optimization as X and Y axis. Green cells indicate profitable results, red cells - non-profitable results. You can use the graph to find smaller patterns for another pass of genetic or exhaustive optimization.
Right-click on the graph to configure the view.
Double-click on the cell to find a parameter set in the result table.
Re-Test Optimization Results
Backtest on the Same Prices Using the Best Parameters
Start the backtesting again but this time enter 3 and 27 (the best set found by the optimizer) in the parameters.
You can see the result on the 2010 equity curve:
There are no falls and the equity curve goes up steadily. This is generally understood to be an improvement.
The Walk-in Optimization
However, the parameters were good enough for the year of 2010. What about 2011 which wasn't used in the optimization? Well, testing of parameters on such a range is called a walk-in optimization. You can do the walk-in optimization and see the backtest results on the first three months of 2011 using the same parameters:
So, the parameters are still good enough at least for the first three months of 2011. Of course, you should not assume that these parameters are good enough for very long. The longest period you can still rely on based on the previous optimization results may be no longer than 1/4 of the period used for optimization. In other words, if 2010 year data was used for optimization, the parameters may be good for the first quarter of 2011 but not longer.
See Also
- Debugging Strategy for details on how to configure and use the chart view and simulation parameters.
- Backtesting Strategy for details on how to read the backtesting results.
- Optimizing Strategy Parameters for details on how to configure the optimization settings.
This Article in Other Languages
Language: | English • español • français • русский • 中文 • 中文(繁體) |
---|