Develop your own auto trading algorithm in 4 steps
Algorithm (algo) trading in the financial markets has evolved a lot in recent years. In the early stages (1970’s and 1980’s), algorithms were used only to collect multiple orders and execute trades, but now algorithms have become more than just a fancy name. They carry out multiple functions, such as scanning the whole market (in thousand of forex pairs), comparing all the currencies to each other in a matrix way, judging the price action, evaluating the possibilities and carrying out the trades. All of this is done in a very short period of time; the most advanced perform out all these functions in a matter of milliseconds. So, they are a very useful tool in reducing your workload. Instead of watching all your forex pairs in the morning, you can use an algorithm which signals you when the price reaches certain levels, or if certain parameters are met. To the ordinary trader or person, just hearing about algorithms would give them an impression of a complex computerised program built based on long algebraic formulas... but in reality the trading algorithms are pretty simple as we will explain.
Quantitative trading has become increasingly popular
1. Find a winning strategy
First of all, you must find a winning trading strategy. The algorithm is going to be built based on something, so finding a strategy is the starting point. For instance, you can use a strategy based on moving averages. Using the 10 and 20 moving averages, you can build a trading algorithm that issues a forex signal when the 10 moving average crosses over the 20 moving average in the daily charts, indicating a new trend has started. Another strategy might be the stochastic strategy in the hourly chart. When the stochastic indicator reaches an overbought level in a downtrend, the forex algorithm will issue a forex signal to sell the pair, as the retrace is over and the chances are that the downtrend will resume. This is a pretty simple explanation, but you always can add more than one indicator. For example, you can build a forex algorithm that spots ‘rangy’ markets and that present you with a forex signal only when two conditions are met: 1) the price reaches the top of the range; 2) the stochastic reaches the overbought area. There are plenty of trading strategies out there, and we have a section of forex strategies on this site, with over 20 trading strategies - so please feel free to use them.
2. Place it in an algorithm
After finding a strategy which is profitable or exhibits high odds of being profitable in an algorithm, you have to translate it in an algorithm. It sounds like a very complicated task but in reality it isn´t. I mean, you can add many indicators and functions to make it complicated but the basic ones are quite simple and I suggest you keep it that way. Same as with forex strategies, the more you complicate them, the harder it is to be successful. With the MT4, you can create your trading algorithm within the platform. The MQL coding language has made it easier to build EAs. Otherwise, you could build the algorithm in other websites like Quantopian.com. Basically, you place the functions and instruct the algorithm what to do when the price reaches a certain indicator. For example, you can give it the function to sell when price meets 50 MA. There is also the option to buy software for building trading algorithms as well... or hire a computer programmer. And then, there is always good old Excel spreadsheets. It looks something like: IF
price reaches MA (50) in H1 chart, WHILE
trending down in H4 chart, THEN
sell. Just one note though, the strategy that you want to build the forex algorithm on should have clear rules in order to be coded. If your trading is subjective and based on experience and intuition, it is impossible to be translated into an algorithm.
3. Back-test it
The third step is the back test your algorithm. You don´t want to risk your account using trading algorithms without testing them first. Most of the forex platforms offer the possibility to back-test trading algorithms against historical price action. It is pretty simple; after you placed the algorithm in the platform you click on ‘tools’ and then ‘history center’ in order to download all the price history. You choose which forex pairs you want to back-test the algorithm on, select the timeframe of the strategy and click ‘download’. After that, you click ‘strategy tester’ at the top of the platform, select the expert advisor that you have built or imported into the trading platform, select the amount of time you wish to run the back-test and click ‘start’. After a while, when the back-testing is over, you click on the results tab. If the results are positive, you have a successful forex algorithm... if the results are negative, you either dump the algorithm or improve it and try it again. The positive performance of the forex algorithm during previous price action doesn´t necessary mean that the algorithm will deliver the same performance in the future, but the odds are pretty high that it will be a winning forex algorithm if it has worked well in the past.
Back-testing the algorithm in the MetaTrader4
4. Maintain the algorithm
Ok, now you have built an algorithm, tested it and deemed it profitable. However, we know that market conditions don´t remain the same. In fact, the price action changes behaviour continually in the forex market. There are periods when the average daily range is 30-40 pips in most pairs, such as in 2013-14 when the market was quiet. Then, as if by magic, the action picked up and we have been trading in a market with a daily range 100-200 pips. But the price action changed quickly, with Monday and Friday being pretty quiet and other days more volatile. So, you have to run maintenance quite often and change the parameters. During quiet periods, you have to narrow the take profit targets that has been set in the forex algorithm, otherwise it will miss them. During volatile periods, you must widen the stop loss targets or you´ll get whipsawed... even if the trading algorithm opens a trade or gives a forex signal when all the things fall in line with the parameters set.
So, a trading algorithm is a useful tool in your toolbox. It makes things easier for a trader by scanning multiple forex pairs or financial instruments and processing a lot of information. Then, they can either open automatic trades on your behalf or give you forex signals which you re-evaluate and act on. But, you have to go through a process in order to build a successful forex algorithm. You should find a profitable strategy which can be coded, translate it into an algorithm and back-test it. It will not make you rich overnight and you must continuously maintain it in order to have constant results. This article has given a general idea of how the trading algorithms are created, so next we will provide a more detailed article on how to code the algorithms.