During my many years of day trading futures markets I have often wished I could get my PC to do my trading for me. Surely it should be possible to automate the process, saving countless hours sitting in front of a screen waiting for trading setups to occur. So, can it be done and, if so, how easy is it? The answer is yes, it is possible, but it is far from a trivial undertaking. Of course, much depends on the tasks you need to automate to implement your trading style. Good brokers offer order types which allow a fair bit of automation of your trading plan.
For example, say you want to BUY if the market drops to a certain level, you could enter an appropriate buy limit order before the market opens. What is more, you could stipulate that if the order is filled, a bracket order is to be created. The bracket order creates two sell orders, one a limit order at your target price, the other a stop loss order at whatever level you choose. When one of the sell orders is executed, the other is automatically cancelled. (Not all brokers offer this facility!).
Alternatively you may be able to submit your buy order with some kind of automatic trailing stop. The idea here is that after your order is filled, the system automatically submits a stop loss order at whatever distance you specify from your entry price. What is more, if price moves in your favour, the stop loss order is continuously adjusted to lock in some of the gains.
All traders should think very carefully about the type of orders which best implement their trading ideas, and look carefully at the types of orders offered by different brokers for the markets they want to trade. Some brokers only offer the limited set of order types provided by the trading exchange, but others offer a rich variety of order types over and above those provided on the trading exchange.
Generally the exchange only supports quite basic order types, so richer order types have to be implemented by brokers using software. As an example, the Globex electronic trading platform used by the CME Group, basically provides just market, limit and stop limit orders. If a broker offers more sophisticated order types, they have to implement them on their own trading platforms. The trading platforms are electronically linked to the Globex system, and translate the more complex orders into the simple order set supported by Globex. So, for example, if Globex does not provide a standard Stop order type, the broker can implement this function for its customers by monitoring market price in real time, and submitting a market order (supported by Globex) if the stop price is touched.
This is all excellent stuff, but over the years I have developed a trading style which requires me to watch the market charts during the trading session and recognize various patterns as they form around support and resistance levels. When I detect these patterns I enter the market with stop and target levels dependent on the patterns formed so far during the trading session. It is not terribly complicated, but it goes far beyond what can be automated using order types provided by even the most sophisticated brokers.
So for many years I have been resigned to watching the markets at whatever inconvenient times they may open and waiting to see if the setup patterns developed. If they did, I entered a trade and manually calculated the appropriate stop and target levels. I was then able to automate my exits by setting up my exit orders as an OCA group (a facility provided by many brokers which specifies that if any one order in the group is executed, the others are cancelled). So, in effect, my method used manual entries and automated exits.
Automating my exits like this meant that I gave up the opportunity to trail my stop loss orders. Rather than trail by fixed amounts, I prefer to trail behind support or resistance levels, and no order types provide this function automatically. So, if I were to trail my stops, I would have needed to watch the trade for its entire duration.
I have enjoyed this form of trading, but it does have drawbacks. If you live in an awkward time zone, as I do, it involves getting up in the middle of the night to trade. Even in less awkward time zones, trading times can clash with other daily activities. Markets move quickly at the open of trading sessions, so it is very easy to make mistakes when you enter trades manually. A few mistakes can make a huge difference to your returns. Psychologically, if you enter a trade manually, it is difficult to walk away from it even if you have automated your exit. So you often waste hours watching each tick of the market to see how the trade turns out. What is worse, you can easily be tempted to change your plan in the emotion of the moment, and not following their trading plan is one of the main reasons traders fail.
So the question became how could I automate the more complex decision making process required to implement my trade entries and determine optimum target and stop levels? It turns out that there are a few systems available which are geared towards setting up trading rules to automate trading processes, but when I looked closely at them they never seemed to be able to do just what I wanted. In the end I decided that the only way to get exactly what I wanted was to write my own software.
To understand how this can be done, you have to be aware that some brokers publish what is known as an API (applications programming interface) for their trading platforms. This is a defined set of protocols which a programmer can implement to connect to and utilize functions of the trading platform. So, for example, instead of logging onto the trading platform and manually entering an order, you can write a program which connects via the API and enters the order for you. This is not a task to be undertaken lightly and it should only be undertaken by an experienced programmer. Anybody unfamiliar with good programming and testing techniques could end up making some very expensive mistakes. Even with an IT background, I set off down this path with some trepidation.
It took me the best part of two to three months to get up to speed in the particular programming language required and to come to grips with the intricacies of the API provided by the broker. At that point, I wrote a pilot program that implemented a greatly simplified strategy and, after very careful testing, I traded it live for a month. It worked brilliantly, and motivated me to continue. A few months later I had a program that implemented all aspects of my strategy, entries, trailing stops (if required), and exits.
At first, I just used to alter program code if I wanted to trade differently. (For example, if I wanted to use 1 minute charts instead of 2 minute charts.) However, this was inconvenient and, while it was OK for me, it was not practical for anybody else using the program. So the next step was to define a control panel which allowed me to alter any of the system parameters without going near the program code.
I have been using the program for some time now, and I would find it very difficult to go back to trading manually. Some of the advantages are obvious. I can set up the PC for a trading session a few hours before the market opens, and leave it to trade automatically without my being present. (Because so little effort is involved, I have started trading two markets each day instead of confining myself to a single market, as I did in the past.) The program executes my strategy perfectly every time. Sometimes, I find myself looking at a chart wondering why it took a certain action, but I inevitably find it acted exactly as it should in the circumstances. If I had been trading manually, I would probably have made a mistake. (You have to have done a lot of testing before you gain this degree of trust!)
I firmly believe that trading success depends on consistently entering trades using a method with positive expectancy. By automating the trading process, I am achieving a level of consistency which was sometimes missing when I traded manually. No more errors due to time pressure, fatigue or inattention.
There are other benefits too which were not so obvious when I started the project. For instance, I am much less exposed to problems arising from internet connection problems than I was before. This may seem surprising, but it arises out of the different way I implement my entries. When trading manually, I use stop entry orders to get me into a trade quickly as soon as support or resistance breaks. This is fine, except for those rare occasions when I put in the order and then lose my connection. That engenders a frantic period trying to reestablish the connection, all the time wondering if the entry order has executed without my being able to put a stop loss order in place.
In contrast, the automated program operates so quickly that it is not necessary to use the stop entry method – it simply enters a market order to open the trade as soon as a break of support or resistance is detected. Then the stop loss and target orders are entered in a matter of milliseconds, as opposed to the minute or two required to enter them manually. So, unless I am immensely unlucky, the worst that can happen is that I miss a trade, if connection is lost before the trade signal occurs, or the program is unable to trail stops if connection is lost after the trade is open.
Another unexpected benefit is the ability to vary system parameters in ways which were impractical, or too error prone, when trading manually. A simple example is the time period of the chart bars monitored by the program to detect trading patterns. In the past I used 2 minute bars, because that was one of the time periods provided in my charting software, and also because if I used a shorter time period, my error rate increased. Now I am not confined to chart periods available in my charting software, and the entries are executed perfectly even with very short bar periods – if I wish to use them.