The Basic Principles of Expert Advisor Coding
If you are using a relatively advanced trading platform, then you may have considered creating expert advisors (EAs) to assist you with your trading or even automating it. However, putting together an EA is not something that should be taken lightly – after all, the reason you are creating an EA is that you want to capture a set of rules that will result in increased profitability, rather than a poorly designed EA that can actually lose you money.
What are the steps in creating an EA?
When software experts sit down to create a program, they don’t just start writing code. Before a single line is written, they have taken the time to design exactly what they want – how is it supposed to behave, what are the inputs and outputs and so on. Exactly the same thing applies when creating an EA – you need to think through your strategy carefully. Only then should you start coding and debugging.
Debugging is not as easy as you think
Once you finally have your code written – and this needs to be done carefully in a well-structured way – you then need to make sure that the EA actually works. While debugging may seem relatively simple, it really isn’t. It is easy to test one or two scenarios, but this is no guarantee that the EA will always work. Instead, you need to look for what are called boundary conditions – strange occurrences that happen at the limits of market behavior. For example, if your EA involves computing a RSI, does it correctly handle the case where the market has risen or fallen for every day in the RSI measurement period?
Expect the unexpected
Boundary conditions are one type of unexpected thing you need to cope with, but you need to take a cautious approach all the way back to your initial strategy. No one can completely predict financial markets, so it’s important that you build plenty of safety margin into your strategy when you are first developing it. For example, steer away from maximum leverage – this will give you much more leeway to cope with unexpected volatility.
Don’t get too complicated
The more complex a thing is, the more likely it is to fail. This is certainly the case with EAs. At the simplest level, the more complexity you put into your EA, the more likely it is to have a bug in it.
However, there is an even more important threat with complexity. Even if an EA performs exactly as designed, as complexity increases it becomes more and more difficult to verify that it is continuing to deliver the sort of trading performance you expect.
High levels of complexity can lead to completely unpredictable results when market conditions change significantly, and even if you manage to confirm that the EA is working correctly in future with back testing, you will end up doing huge amounts of unnecessary work. Stick to something simple that reflects your trading strategy and then perfect it, rather than trying to build a better mousetrap.