This page is obsolete and no longer maintained. Please browse the blog article for information regarding backtesting on different custom charts.
This is a step-by-step guide to help you with testing EAs on various price based charts using tick data. The backtests will be performed with 99% modeling quality.
You will need the following software components (links provided in the list below):
- Metatrader4 with an online broker connection,
- Tick Data Downloader,
- CSV2FXT script(s) for converting downloaded tick data into backtesting data which can be utilized by MT4. You’ll need the files that match the chart types you wish to backtest (RangeBars, Median Renko, Renko, PointO, Tick Charts),
- MQL code snippet to enable your EA to be properly backtested using tick data,
- Tick Data Suite to perform the backtest.
Step 1 – Downloading tick data needed to perform the backtest
There are several ways to acquire tick data for the period we wish to perform the backtest on. I use the Tick Data Downloader program, which is simple to use.
Once you install and start the program you’ll see the following window:
The grid is used to select individual symbols with corresponding date span selectors for downloading data. Use this grid to select the symbol(s) needed for backtesting and the date range desired for the backtest.
For this guide, I will only focus on one symbol ( EURUSD, the period from 10.05.2015 to 10.11.2015 ):
Once EURUSD is selected plus the “Download from – to” field is set to the desired date span, you can begin downloading tick data by pressing the “Start download” button. The download process will begin and it will take some time to complete. When the download, which will be indicated in the Status column, you’ll need to click the “Export data” button.
When all tick data is exported to a CSV file, you need to copy the file from the application’s data output directory to your Metatrader’s <data-folder>/MQL4/files folder.
Please note the name of the exported CSV file as you will need to enter this name into the “CsvFile” input of the CSV2FXT script.
At this point, you can close the Tick Data Downloader program and move on to step 2.
Step 2 – generating your .FXT and .HST files for time-based charts
At this point, you already acquired tick data from an external source, generated a valid CSV file containing tick data for the selected symbol and placed that file in your data folder’s MQL4/files sub-folder.
Next, you need to start your Metatrader terminal (don’t start TDS at this point, as the script will not run properly under TDS) and ensure that it is connected to your broker’s server (live or demo).
You will also need the appropriate CSV2FXT script modifications* in your experts/scripts folder of MT4. They will be accessible from MT4’s Navigator window under Scripts:
Each modification is used for generating a different price based chart format:
CSV2FXT_medianrenko_mod_b574 is used to generate a synchronized .FXT & .HST file pair for a Median Renko chart of a symbol you will be backtesting
CSV2FXT_pointo_mod is used_b574 to generate a synchronized .FXT & .HST file pair for a PointO chart of a symbol you will be backtesting
CSV2FXT_rangebars_mod is used_b574 to generate a synchronized .FXT & .HST file pair for a RangeBar chart of a symbol you will be backtesting
CSV2FXT_renko_mod_b574 is used to generate a synchronized .FXT & .HST file pair for a Renko chart of a symbol you will be backtesting
CSV2FXT_tickchart_mod_b574 is used to generate a synchronized .FXT & .HST file pair for a Tick chart of a symbol you will be backtesting
CSV2FXT_*_mod_b574 scripts are compatible with MT4 builds 574 or higher. They have been successfully tested with TDS
*) These are optional premium addons to the charting plug-ins, which are only available in the PRO version of the plug-ins available on this website.
Please contact us if you already own our plug-in(s), but you don’t have the corresponding CSV2FXT file and you would like to purchase it without having to re-order the plug-in.
Since we will be backtesting the EURUSD pair we need to open a 1M chart of EURUSD and drag the selected CSV2FXT script modification onto that chart. This will display a settings window for the selected chart type:
After the settings are defined you need to press [OK] and the preparation of EURUSD.FXT & EURUSD.HST files will begin. The script will update the percentage of completion on the 1M chart:
This will take some time to complete and once done, the following modal windows will pop up:
The choices you have are [YES] and [NO].
You should choose Yes if you will be backtesting under the same MT4 terminal.
If you choose No, you will need to manually copy the EURUSD.FXT file to your selected Metatrader’s tester\history folder and the EURUSD.HST file into your selected Metatrader’s history\ServerName folder. This may be necessary if the files are very large. However, for this guide, I will assume that you’ve pressed Yes and the generated files have been copied into the correct folders.
You’ll now need to shout down MT4 and move to the next step.
Step 3 – Preparing your EA for proper testing on price based charts
As of version 2.20 of MedianRenko, Renko, and PointO as well as version 3.20 of RangeBars this step is no longer required – you can skip down to step 4.
You’ll need to include 2 lines of code in your EA so that it can be to be properly backtested using tick data & price based charts (especially MedianRenko).
To demonstrate the process, I will use the MACD Sample EA, which is included with every MT4 distribution in an uncompiled MQL format:
You need to open the EA file in the MQL editor. This can be done by right-clicking on the EA name (MACD Sample) and choosing Modify from the popup. This is how the code will look like in the original form:
Now we need to include an MQL code snippet, which is distributed and automatically installed with the plug-ins. This is done by adding a #include <CustomChartingBacktest.mqh> statement at the beginning of the EA code:
plus adding the if(skipFirstTickOnBacktest()) return; function call at the top of the OnTick(void) function:
This will ensure that you EA backtests properly on price based charts (especially on Median Renko charts).
You don’t need to remove this code from your EA for live or demo operation since the function will only work when the EA is being backtested.
Once your EA is modified in the same way as the presented sample EA, you need to compile the EA by pressing the Compile button, which is located on the MQL editor’s toolbar and move to the next step if the EA complied successfully.
Step4 – Backtesting you EA using Price based charts & Tick Data
You’ll need the Tick Data Suite application (TDS) for this step – if you don’t have it yet, you can download a 7-day trial version and give it a try.
Make sure that the application is properly installed and configured for use with you MT4. First, you’ll need to close your MT4 and now simply run the tds.exe program, which should be located in your MT4 folder:
Your MT4 terminal will be loaded and patched at runtime by the TDS application, which will ensure proper operation when the backtest is performed.
Backtesting can now be performed by bringing up the strategy tester window (Ctrl-R) in Metatrader and setting the following parameters:
Expert Advisor – set this to the name of your EA, which has been modified in the previous step,
Symbol – set this to EURUSD (as we’ve downloaded and prepared the tick data for this symbol)
Period – set this to M1 (all backtesting using price based charts will be performed on the M1 period)
Model – set this to Every Tick
Visual mode – check this box, if you wish to view the chart as your EA is being backtested
The backtest will begin once you press [Start]
Step 5 – Analyze and perfect your trading strategy or robot
When you come up with an interesting strategy or find a promising robot that proves to be good in the backtests, it is time to take your analysis a step further. There is an excellent tool for this, which is called Quant Analyzer and is made by the same company that gave you the Tick Data Downloader.
Click to try out the Quant Analyzer
DEC
2012