Note: Generally speaking, creating a trading system is not a simple subject. Any investor who wants to implement an automatic trading system should work closely with their brokerage to make sure that they understand the tools and are using them correctly. There are also many consultants who are proficient with brokerage-supplied automatic trading tools. A professional consultant can be a good resource for double-checking your trading methods and calculations, or for implementing more complex strategies. And, of course, all investing involves risk.
Trading Systems, Blackjack, and Backtesting
A trading system is a set of pre-defined rules that are used to trade a market. The trading system can be executed by running a computer program (very precise, efficient, and reproducible) or it can be executed manually by a person (less precise and less efficient). Automated trading systems have a few advantages over other methods of trading. One key advantage is that they can be tested to see how well they would have performed if they had been used in the past. Another advantage is that, by definition, they are disciplined, relying on a fixed set of rules rather than emotions. Yet another advantage to an automated trading system is that it can be run unattended, freeing you up to do other things. It takes some time to plan and implement, but an automatic trading system can be one of your most powerful trading tools.
Testing a trading system is similar to testing a blackjack system, but with one major difference. Blackjack systems can actually be PLAY-TESTED, whereas markets can only be BACK-TESTED or RUN-TESTED. A blackjack test engine is based on probabilities that are fully determined beforehand based on the total number of cards in the deck at any given time (that is, the total number of cards minus the cards that have alread been played). The first hand dealt to the player has a certain probability of beating the dealer's hand, based on the card that the dealer is showing. As the cards are played and removed from the deck, the probability of receiving a pair of cards that beats the dealer's visible card changes. In addition to knowing the general odds based on the number of cards remaining, a blackjack player is allowed to see the cards as they are played, therefore they can always know the EXACT range of probabilities for the next hand, and bet accordingly.
In contrast to a blackjack system, which can be play-tested, automatic trading systems can only be back-tested or run-tested. Back-testing involves testing a strategy against a certain period of time in the past to see how it would have performed. The range of time tested can be anywhere from days to decades, and certain types of systems should be tested against different periods of time depending on the economic climate. Run-testing involves running a trading strategy real-time in the present, but with no real trades being executed (i.e. paper trading). The results are tracked as if the trades were actually made in order to test the strategy against current price action.
The future price of a market instrument has no pre-determined set of probabilities. Instead, market prices are determined by a massive, ever-changing group of participants, who combine to exert buying and selling pressures in the form of bid/ask prices. These participants include individual traders, ETF and mutual fund managers, and proprietary (prop) trading firms from all over the world. At any given time, some of them are trading manually while others are deploying software systems that trade automatically. Some are speculating on a rise in price and some are speculating on a drop in price.
This results in a large number of highly-liquid trading instruments to choose from, often with relatively narrow bid/ask spreads. The exchange traded fund SPY, which tracks the S&P 500 index, trades 200 million shares daily on average (with spikes to 600 million plus on some days) and Citigroup stock trades over 500 million shares daily with spikes over 1 billion shares on certain days.
In addition to the large number of market participants and the enormous number of shares traded, there are many variables that traders/investors use when deciding what names are worthy of their investment. These include fundamentals data such as sector or index inclusion, P/E ratio, EPS, market cap, dividend yield, and insider transactions. Also included in the variable mix are the technical (chart-based) data, which are indicators derived from the price of the instrument in the recent and/or distant past. These include money flow indicators, momentum oscillators, and moving averages.
Other variables that can influence market prices are company news, macroeconomic conditions, major world events, and governments/politics. All combined, these variables lead to an environment where the exact price of a stock (or other trading instrument) cannot be determined before-hand. This does not mean that there are no probabilistic trends to be discovered. It just means that the probabilities are not known exactly. A trading system involves using those variables to decide which instruments to trade, and at which points to buy and sell those instruments. Back-testing can give you some confidence in your automatic trading system, but of course there are no guarantees for the future.
Here is what you will need to do in order to implement an automated trading system:
Step 1: Get some software
A number of platforms can be used to trade automatically. For instance, Tradestation offers a programming language called EasyLanguage, which can be used to track stock prices, create custom indicators, and trade automatically based on pre-defined trading setups. E-Trade offers the ability to trade automatically using the Excel Manager function of their Power ETrade Pro trading platform. Real-time quotes can be monitored using Excel and custom cell formulas can be used to trigger opening or closing orders of any type (e.g. market, stop limit, and trailing stop orders). Ninja Trader is another popular platform that allows automatic trading using their NinjaScript programming language. CoolTrade offers an automatic trading engine which requires no programming and works with several major brokers, including Interactive Brokers, TD Ameritrade, and ETrade.
Each of these providers has robust technical support available along with substantial online user communities, so help is always there if you need it. Regardless of which system provider you choose, the key elements to an automatic trading software platform are:
- The Ability to Trade Automatically Based on Programmable Buy/Sell Signals
- The Ability to Back-Test or Run-Test Your Strategy
- Quality Data
Step 2: Pick a trading instrument
If you want to implement an automatic trading system, you need to pick a good instrument to trade. A good trading instrument generally has a lot of daily volume (liquidity) and tight bid ask/spreads which leave little room for price slippage. If there are not enough shares traded on a daily basis or if the spreads are too wide, your backtesting results will be less accurate and when you try to trade it in the real world, your system may not be able to execute the trades that you require at a favorable price. The good news is that there are plenty of stocks, options, and futures contracts available that have millions of daily trades and 1-2 cent spreads, so it's not too difficult to find a good instrument to trade.
Another factor that you may want to look for would be instruments that seem to bounce back and forth off of long-established support and resistance levels. This pattern is easy to work with as these types of instruments can be played from the long side when they are oversold and the short side when they are overbought.
Although good liquidity is usually desirable, you can also take the opposite approach if you'd like. Strategies utilizing instruments with low liquidity and wide spreads can offer a favorable advantage for a trading system. However, they are usually more complex to execute succesfully since price slippage is more difficult to manage.
Step 3: Pick a strategy
Automated trading strategies are based on a set of rules that you program (or someone else programs for you). These rules define when to enter a position and when to exit a position. The position can be either long or short, and a single strategy can utilize long and short positions by defining rules for both. These trading rules are based on the same parameters as manual trading strategies, fundamentals (company characteristics) and technicals (price action).
For stocks and indexes, typical company fundamentals can be used to signal favorable entry and exit points. Things to consider would be measures of value and payout income such as P/E ratios, estimated earnings, dividend payouts, and optionability. In addition, parameters such as short interest can be taken into account to determine when an entry or exit point looks favorable.
Using technical indicators, you can design an automated strategy around moving average crossovers, price breakouts, reversion to the mean, and dozens of other methods. For instance, a simple strategy could use Bollinger bands and stochastics to control entry and exit levels, going long at oversold levels and short at overbought levels. Regardless of the strategy, it is important to include risk management measures including well-defined stop-loss and profit-taking levels.
Step 4: Backtest and Interpret
Your software should include a back-testing component. This component consists of a software "engine" that can execute your automated strategy based on past price data. Your system can then be back-tested for any period of time to see how it would have performed. This can be lately or at any time in the past, such as during specific bear and bull market periods and high and low levels of volatility. Your software provider will determine how much price data you have to work with, and how far back you can back-test.
Once your back-test run is complete, the system will show you several results, such as the percentage of winning and losing trades, the largest drawdown and largest gain, the net results of your system over time, and an equity curve showing how your money either grew or shrunk over time. Needless to say, you are looking for results that show an increase in equity over time, with small drawdown periods. Be forewarned that every trading strategy experiences drawdowns (i.e. periods of consecutive losses). This is why stop-loss limits are important. Even though your back-tests may show that a system did not suffer a certain level of drawdown in the past does not mean that it won't happen when you run the strategy in the real world.
Step 5: Implement the strategy
Once you are confident in your strategy, you can turn it on and let it operate. You can monitor the results in real-time to see how it's performing. In addition, you can stop and start it as you please, making adjustments along the way. Be aware that if your computer experiences an error or power outage, your system may stop executing, possibly leaving you with a position that will not be exited at the intended time. If this happens and you feel that you must intervene, you should be able to call your brokerage and work with them to monitor your account and execute your trades.
Automated trading strategies are becoming more and more common among individual retail investors as software trading tools become more and more powerful. Many pros and amateurs have been successfully running automatic systems for years. The keys to success are a solid grasp of the tools and methods along with the skill in understanding company fundamentals and price action.
* A Note on Network latency and co-Located Servers
In order to place a trade from your computer to the stock exchange, it must travel along the internet routing system. This network journey introduces a delay between the time your broker's system interprets your command to buy or sell and the time the trade is received by the exchange to be executed. This delay is known as network latency and will introduce some (usually slight) delays in your trading execution. You can be confident, however, that the link between your broker and the exchanges are lightning-fast if you are using a well-established broker, so that segment will not really be introducing much of a delay.
Large proprietary-trading firms employ co-located (CoLo) servers, which means that the automatic trading system is actually physically located at the exchange. The automatic trading code is developed by a team of market analysts and software developers and is then uploaded to a computer (server) that sits in a cabinet at the stock exchange. This results in faster trade execution, lower slippage, and the ability to throw lightning-fast head-fakes through modified or cancelled orders. Here the machines trade against the manual traders, as well as against each other, hoping to scalp profits from the various spreads that come and go throughout the day.
Co-location certainly creates an advantage for the big shops, but the average trader does not need to concern themselves with network latency if they have a broadband connection and a reasonably new computer. With little exception, your trades will be executed within a few seconds if you are using one of the higher-tier retail brokerages and are working with a trading instrument that has adequate liquidity.