Mark Thomas — Trade On Track
An important step in the development of an automated forex trading strategy (trading robot or EA) is the testing phase. Testing should involve back-testing as well as forward-testing and be performed as accurately and extensively as possible. No amount of testing can absolutely assure future results, so the idea is to be as sure as possible!An important step in the development of an automated forex trading strategy (trading robot or EA) is the testing phase. Testing should involve back-testing as well as forward-testing and be performed as accurately and extensively as possible. No amount of testing can absolutely assure future results, so the idea is to be as sure as possible!
The answer seems obvious … so that you can be reasonably sure of what you’ll get from your automated trading strategy in future. Testing means you can see how your strategy has reacted in the past to different market conditions. You can gauge whether the strategy has worked against different currency pairs or different time frames. You can test variations of the strategy to see what works best overall, and what should be avoided. Testing a strategy can give you confidence to keep using the strategy in future, if the past results have been profitable and consistent.
How do you test?
To back-test a trading strategy, you first need to obtain some historical data. The historical data contains information about price levels in the past, such as open, high, low and close information. You can get historical data for daily intervals (this is the easiest to get), where each record contains open, high, low, and close prices for each trading day. More detailed data can also be obtained for shorter intervals such as hourly, 5 minute or even 1 minute intervals. Generally, the shorter the time frame, the more accurate you can make your back-testing.
The first place to look for historical data is your broker. Many brokers offer free data downloads if you have a live account open with them, and the data is usually of quite good quality. Your broker’s historical data will also most likely be the same data that is used to draw the charts that you trade off, so it’s easy to look back through your charts and visually check how your strategy plays out.
There are other sources of data too, some are free, some involve a cost. It’s a good idea to obtain good quality data from a number of different sources for your back-testing. Data can vary, so it’s good to be able to test your strategy on the different data sources to see if it holds up. Dukascopy (http://www.dukascopy.com) is a good source of data, and you might also try Gain Capital (http://ratedata.gaincapital.com/)
To actually perform the back-testing, you’ll need a software program which processes the historical data and executes your trading strategy using that data. Trades aren’t actually executed of course, the execution is just emulated within the software. Based on your strategy, the program can keep track of when the trades would have been taken, how profitable they were, how many winners compared to losers you had, and many other statistics related to the performance of your strategy.
The most accessible software program to do this is Metatrader 4 (MT4). It has a built-in strategy tester and you don’t even need to download any historical data first – it will do it for you automatically. The downside to MT4 is that you first need to write an EA which implements your trading strategy. Writing an EA involves writing a computer program in the MQL4 language – the scripting language that MT4 understands. So, you’ll need to be able to program in MQL4 or get a programmer to do it for you if you want to go down this route.
If you like to get your hands dirty in computer code, you can also just write a program to back-test the strategy using the historical data. There is usually a library available for your favorite language which contains the indicators and other statistics you may need to test the strategy, such as EMAs, SMAs, MACDs, RSIs and so on. For instance, there is a freely available library called “profitpy” for the Python programming language which allows you to build a strategy tester.
For non-programmers, check out http://www.thinkingstuff.com. Their system allows you to develop and back-test strategies using point-and-click technology. What this means is that you don’t have to write any programming code, you just use your mouse to select options and the Thinking Stuff software builds the back-testing code for you.
Other related sites for strategy testing include: http://forextester.com/ and http://forexsb.com/
Back-testing and getting good results doesn’t necessarily mean that you have a good automated trading strategy. There could be flaws in your back-testing procedure or data which is affecting your results. Some common back-testing problems include:
- Optimizing (or curve-fitting) the strategy too much. If you tweak and re-tweak your trading strategy to give the best results possible using the data that you have available, then you run the risk of tailoring it too closely to that data. If there are too many parameters or filters involved to make the strategy work, then you may have problems in getting that strategy to give satisfactory results in the future. Sometimes you’re better off NOT optimizing so much – give the strategy a little room to breathe, make it a little simpler or more flexible. A lightly curve-fitted strategy is likely to give better results in the future.
- The data isn’t detailed enough. If you have 15 minute historical data and you’re testing a strategy that works on the 15 minute chart, then the accuracy of back-testing is going to be quite limited. For instance, if in one 15 minute period (one 15 minute bar) price shoots up and reaches a point that would have hit your target and it also reaches down to a place where it would have taken out your stop loss, how do you determine whether your target was hit first or your stop was hit first? The answer is, you can’t. Without going down to a lower time frame or even tick data, there is no way from your historical data that you can tell whether price went up first or down first. You only have open, high, low and close information. So, if you’re data is limited in detail, your back-testing program should take the worst case scenario in this example and assume that the stop was hit first.
- Data is bad quality. Some free data sources are terrible quality. There are gaps in the pricing (from the close of one bar to the opening of the next bar), there are incorrect prices, and sometimes there is just no data where there should be some! Try to obtain decent quality data and when in doubt, try to obtain data from a number of sources and get the best results possible across all sources.
All of the above has dealt with back-testing, but forward-testing is also important. Forward-testing an automated trading strategy involves running the trading robot in a live (or demo) trading account and monitoring the results over a period of time. You may be surprised that something that works really well when back-tested, does not perform very well when run on live data. This can be because of the curve-fitting problem mentioned above, or because you’re striking market conditions that haven’t been tested in the past. Forward-testing can also uncover other problems in your back-testing that you weren’t aware of, so it’s essential to forward test, preferably on a demo account before moving to a live account.
Once you’ve back-tested your strategy on a good sample of historical data and you’ve forward-tested it too, you can be confident that your future (or at least, near future) results will be fairly similar to the results you’ve had to date. Never just let a trading robot loose though – always monitor what it’s doing because markets can be unpredictable you want to be ready to pull the plug should something go wrong.
Latest posts by admin (see all)
- How To Trade The Fractal Indicator - April 3, 2017
- How to Use Candlestick Patterns to Start Winning More Trades - March 19, 2017
- Weekly Review Strike 3.0 - December 16, 2016
Winner’s Edge Trading, as seen on: