From coding with lightweight, functionality heavy text editor's like VIM through to the full suite of automated trading capabilities of cTrader Automate, read on below why automating your trading strategy may be right for you..
Trading Forex and earning a decent living while being location independent is cool. But if you could hire someone to do the trading for you, who does not sleep or take a break, that would be even cooler. Automated trading is exactly what it describes, which is using a computer algorithm or artificial intelligence to follow a trading strategy that works mostly autonomously.
Being human has its perks, like the ability to enjoy fine dining and company of likeminded friends, but we have some built-in limitations, namely fatigue and making mistakes when it comes to paying attention to detail. Most day traders soon realize how tedious the task of trading is as one needs to constantly scan several markets and make split-second decisions. This one of the reasons why trading experts advise newbies to trade on larger timeframes like daily or even weekly charts when they are just starting out.
By contrast, computers are surprisingly good at doing tedious tasks. Once you program the trading strategy and create an algorithm or robot, it can execute a trade with precision, and it does not even need to sleep or go out for dinner. No wonder automated trading has been gaining traction over the last two decades. In fact, the latest report from financial portal CNBC reported that almost 80% of all trading activities in the U.S. equities market are now controlled by algorithms.
While U.S. equities are great assets to trade, the global foreign exchange market has a higher level of the trading volume. Furthermore, the currency valuation models rely on global macroeconomic data, which is much harder to assess and it leads to much higher volatility compared to equities. Hence, Forex traders have historically strongly relied on technical analysis compared to traders who mostly trade commodities or equities. Furthermore, given the fact that the foreign exchange is the largest decentralized market in the world, it offers more potential for scalability of automated trading. As a result, large hedge funds and institutional traders have embraced algorithms and some of the best strategies in the Forex markets are now automated.
What this detailed guide will cover:
- Pros and Cons of Building an Automated Trading Strategy
- Pros of Automated Trading
- Cons of Automated Trading
- Step by Step Process of Developing an Automated Trading Robot
- Defining the Strategy
- Back Test Your Automated Algorithm
- Forward Test Your Automated Algorithm
- Hosting the Automated Strategy
- Overview of the Major Automated Trading Software
- MetaTrader 4/5 and the MQL Language
- Honourable Mentions
Pros and Cons of Building an Automated Trading Strategy
Pros of Automated Trading:
As we mentioned earlier, most human traders suffer from a key disadvantage compared to algorithms, the human error. Have you ever placed an order to sell 10 standard lots of EUR/USD then realized your money management strategy recommended only 1 standard lot? Did you immediately close the order with a loss or wait for +1 pips on the terminal?
You see, we all make mistakes and take emotional decisions, and that's part of being a human. We are great a coming up with creative ideas, but even the most professional traders would suffer from making mistakes. While we like to think that we are rational decision-makers, there is a whole field called Behavioural Economics that describes how our biases lead us to act irrationally, often against our own best interest.
By automating the trading strategy, traders can eliminate human errors and take emotions out of the trading decision-making process. Consequently, the performance of an automated trading robot becomes much better compared to letting a human or even a group of humans to trade the same strategy. An automated trading algorithm can demonstrate a level of discipline that human traders can only theorize about but cannot achieve in practice.
Building Confidence with Backtesting
Have you ever tried to conduct backtesting? When humans backtest, we see all kinds of non-existent patterns in the market that are not there. It is because human brains have evolved to crave order, even when there is only chaos.
Famous mathematician Benoit Mandelbrot wrote in his book, The (Mis)Behavior of Markets that our "brain highlights what it imagines as patterns; it disregards contradictory information. Human nature yearns to see order and hierarchy in the world. It will invent it where it cannot find it."
But if you code an algorithm with some mechanical trading rules, that you created by using logical patterns, and let it comb through the data set, it will likely make a more accurate observation and only find patterns which are actually there.
Reducing Latency and Improving Trade Executions
Automated trading robots can be placed in a building next to the exchange to reduce network latency. You see, the faster you can receive the price data, the faster you can place the trade. The difference between a few milliseconds can turn a winning strategy into a losing strategy.
Let us say the U.S. non-farm payroll figures were released and a trading algorithm is hosted within few hundred meters of the broker. It can communicate with the server much faster if the algorithm was hosted in Australia. Hence, automated trading always wins when your trading strategy relies heavily on trade execution.
By comparison, human traders are severely slow to react and it would take at least a few seconds for even the most experienced trader to analyse some news, then act on it. Asking a human to do high-frequency trading would be like asking a man to fly, without wings.
Ability to Trade More Assets and Diversification
Have you seen those movies about financial markets where traders use six monitors to scan different markets and timeframes? Well, even with 30 monitors, there is a limit to how much information a human trader can process at a given moment. But automated trading algorithms do not suffer from such cognitive bottleneck.
If you host the robot on a server with some decent hardware, it can constantly scan hundreds or even thousands of assets on a given moment and trade all of them simultaneously. Hence, automated trading offers a much higher degree to diversification compared to employing human traders.
Cons of Automated Trading:
Dealing with Computer System Errors and Network Failures
In December 2020, the largest search engine and cloud computing service provider Google, yes that Google, went offline for almost an hour. The consequence was total chaos and missed appointments, school holidays, and lost business opportunities around the world.
If Google can go offline, imagine the type of computer errors and network failures you might need to deal with while hosting your trading algorithm in a small data centre. The fact is that while humans make errors due to fatigue and not paying attention, computer systems can simply crash and breakdown completely. So missing trades due to hardware failure and other network issues are a risk automated trading strategy need to consider.
Algorithms Require Human Oversight
When you are trading with a large sum of money, leaving a computer unattended is never a good idea. While algorithms are good at executing a trading strategy during predictable market conditions, it cannot be left alone if there is a sudden spike in volatility. Furthermore, algorithms require constant performance monitoring to see if it is working as intended or variables need to be tweaked to make it more efficient. Hence, regardless of how autonomous an algorithm is, it will always require some degree of human oversight.
R&D Cost, Intellectual Property Issues, and Cyber Security
If you just want to use a basic strategy like moving average crossover, then you can probably find the codes readily available for free on the Internet. If you have a unique trading strategy with rather straightforward rules, you can hire a programmer to do the coding for you. But more complex trading strategies with a lot of if and but rules take longer time to code and it can be very expensive to hire full-time programmers.
Furthermore, trading strategies are easily replicable, and the risk of intellectual property theft is a real problem. If you have hosted your automated trading robot on a remote server, it can be hacked, and the algorithm could be copied. Losing a million dollars would be preferable than losing your life's work due to compromised servers. So, when you develop a trading robot, keep these things in mind.
Step by Step Process of Developing an Automated Trading Robot
A trading robot follows similar rules as human traders, it is just executed by a computer program. Hence, the process of building an algorithm is very similar to creating a day trading strategy that human traders have applied for decades.
Defining the Strategy
The key difference between an algorithm and a human trader is there is no room for analysis. All rules of the strategy must be clearly defined, and contingency plans must be defined as well. You cannot leave any strategy gap while building a trading robot.
If you are creating a trend following strategy, you need to find a way to tell the algorithm what parameters of an indicator it needs to monitor and at what value, it would consider the market to be trending. For example, a human trader may wait for a moving average crossover before considering a change in trend. Similarly, if the same strategy to be traded by an algorithm, you need to write down the moving average values, the number of periods, and if it is a simple or exponential moving average you want the algorithm to monitor. Furthermore, if you want the robot to trade only during a trending market as defined by the Average Directional Index (ADX), you need to explicitly instruct it to trade only when ADX is hovering above a certain value, such as 20 or 25.
So, just like a mechanical day trading strategy, the first step to build an automated trading robot is writing down the rules for entry, exit, and trade management.
Also, you need to write down how the money management aspects and detail risk mitigation strategies for the robot to follow. How do you calculate the stop loss? Are you using any particular indicator like the Parabolic SAR? Should it calculate stop size using the Percentage Risk Model or use the same lot size for all trades? All these details need to be programmed.
Back Test Your Automated Algorithm
Once you have written the program, the next step is to test it out on historical data to see how the algorithm performs and if there is any bug in the program. At this stage, you can also tweak your strategy to increase performance. But make sure that you are not engaged in curve fitting, which is basically making the strategy tuned to historical prices instead of following the original rules of the strategy that you built from deductive reasoning or logical pattern.
Forward Test Your Automated Algorithm
Once you are satisfied with the backtesting results, now you need to move on to forward testing stage. In forward testing, algorithm developers mostly trade paper money using demo accounts for months and monitor the performance of the algorithm closely. Here, some knowledge of finance is required as you need to figure out statistical performance using profit factor, Sharpe ratio, and risk to reward ratios of the strategy in real-time.
If you feel confident that your strategy is working on a demo account over a period, under different market conditions and handling the trades well, you will put the algorithm on a live account and hope for the best.
Hosting the Automated Strategy
While it is tempting to just keep your home computer running 24/7, it is a bad idea. Professional traders often rent Virtual Private Servers in data centres to host their automated strategies as it offers better network latency, ensures uptime and reliability of the program.
There are plenty of data centres geared towards hosting trading algorithms and offers various prices depending on the speed of processor or amount of RAM. However, keep in mind that the closer you host your automated trading robot to your broker's server, the better. So, if you are trading with an Australian broker with servers in New York, make sure you host the trading robot in New York, not in Sydney.
Overview of the Major Automated Trading Software
Nowadays, almost all major trading platforms come equipped with automated trading capabilities. If you want to develop more sophisticated algorithms, you can also opt for writing it using traditional programming languages like C or Python. Regardless of what programming platform you use, a good code editor is essential to developing trading algorithms. While there are more complex coding platforms available, you want to keep things simple and use a reputable text editor to write code.
For example, Vim, a universal text editor developed in 1991 by Bram Molenaar, is very popular among veteran coders because it offers an extensive list of plugins and supports a large number of programming languages and different file formats.
When it comes to VIM, aside from its standout functionality as a text editor, there is the benefit of knowing that you are also supporting a very worthwhile cause. VIM is what is called "charityware".
Bram Moolenaar, has very generously donated his time as well as all the proceeds from VIM to a very worthy cause - supporting disadvantaged children in Uganda. Through the ICCF (International Child Care Fund), a charity registered in Holland, an education and support is provided to vulnerable children at the Kibaale Children's Centre.
cTrader comes with a full suite of automated trading capabilities called cTrader Automate. Coders can leverage cTrader's modern C# API and use the integrated development environment. Also, the platform offers an Open API that traders can use to connect their external trading algorithms to execute trades on the platform.
While cTrader is relatively new compared to more established trading software like MetaTrader, it offers a range of new services, like the API capabilities, for algorithms.
MetaTrader 4/5 and the MQL Language
MetaTrader has been dominating the Forex trading industry for more than a decade, and for good reasons. It is reliable, widely used so there is a network effect of using its popular MQL programming language, and there is a list of the extensive indicators and trading algorithms already available for free that anyone can use.
MQL4, the programming language used in MetaTrader 4, used a syntax that is very similar to a popular programming language like C++, C#, C and Java. The similarity in Syntax made it easy for people with programming knowledge to learn the MQL4, which contributed to its rising popularity. Also, it made the learning curve much easier to cope with.
Furthermore, the built-in strategy tester in MetaTrader enabled developers to easily import historical price data and backtest their algorithms and tweak variables as needed, on the fly.
Prior to the release of MetaTrader 4, automated trading belonged to more sophisticated hedge funds and large institutional investors with deep pockets. However, when MetaQuote introduced the MQL programming as a built-in option for MetaTrader for free, it was an instant hit and it helped democratise automated algorithms. Anyone with basic programming knowledge could, and still can, write their own technical indicators and automate even complex trading strategies with extensive rules with the platform.
While cTrader and MetaTrader 4/5 are two of the most popular trading platforms, there are a few notable platforms out there that make life much easier for developing automated trading platforms. Two of these platforms are TradeStation, uses EasyLanguage, and the once-popular technical analysis platform NinjaTrader, which uses C# based NinjaScript.
While both TradeStation and NinjaTrader are very capable of trading platforms, the limited Forex brokerage option creates a disadvantage for using these platforms. Nonetheless, if you are interested in building automated algorithms for equities and other assets, these are some of the platforms you should definitely consider.
On the surface, automated trading sounds an exciting way to generate some passive income. However, keep in mind that developing a successful trading robot is not an easy endeavour.
The first thing you should do when considering developing an automated trading robot is this: try to assess the actual feasibility of automating your trading strategy. If there is a lot of room for interpretation in your strategy, where you make gut decisions, then your strategy may not be suitable for automation. Remember that robots are not that smart, yet. These programs need clear instructions, which are also quantifiable. So, any qualitative aspects of your trading strategy would be lost when you translate it for a computer algorithm.
Secondly, you should consider the upfront cost associated with developing a trading algorithm and conduct a cost-benefit analysis of some sort. The amount of time and resources you need to invest may make it financially not feasible. If you have a $10,000 trading account and investing $5,000 to develop a trading robot that generates only 20 per cent return a year, then it would take a long time before you would even reach a breakeven point on that investment. After all, Forex trading or any trading is a business, and you should treat it as such. Also, do not forget the ongoing costs of servers and monitoring the algorithm.
Once you are satisfied with the answers to these aspects of developing an automated trading system, go ahead and try out your system in a forward testing environment with a demo account. Only after you are certain that it is a profitable strategy, invest your hard-earned savings in an automated trading robot.