How Automated Trading Can Increase Your Trading Profits

A lot of technical analysis involves watching indicators for signals, and then trading based on the signals. As I’ve discussed in a previous article, “One Behaviour That Puts Great Traders Above The Rest”, you should be noting down all of your trades in your trading journal, and as you gain more experience you should be able to identify the setups that make you the most money.

What if you could program a computer to automatically identify these setups and enter trades automagically? What if you could free yourself from the tyranny of the charts?

“Impossible! Technology can’t replace the skills and experience I’ve built up over 20 years sat on my ass watching charts all day!”

— Some baby boomer Twitter chartist

Alright, I’ll admit it. I made that quote up.

You got me.

Haters will say it can’t be done, but they’re wrong. It can be done.

The amount of financial data available is astounding. You can get the price feed directly from most cryptocurrency exchanges via their application program interface (API), and, as you might expect, it’s just a bunch of numbers.

Unsurprisingly, computers are way, way, WAAAAAAAAAY better than humans at doing math. If you can identify the setups that make you the most money, so can a computer. We’re talking about technical analysis here, not fundamental analysis, that’s a whole other kettle of fish.

A guy I keep banging on about, Ed Seykota, had a pretty good run in the 70s and 80s. He pioneered systems trading, and racked up gains of 250,000% over a 16 year period in his model account. And yes, that’s the correct number of zeroes.

Those kind of gains are unheard of nowadays. At the advent of computerized trading, he had very little competition. Gains have been eroded, but you can still make excellent returns from automated trading systems.

Technical analysis is the study of charts. TAs watch the price looking for patterns, and use indicators to determine market conditions. An indicator is just a mathematical function on the price and/or volume of an asset. And a pattern is just a arrangement of prices over a timeframe.

This means a technical trading strategy boils down to numerical analysis, and math problems. Computers are much quicker, and more accurate than humans at solving math problems, so why not tell your computer what the rules of the game are and let it trade for you?

What is an algorithm?

The dictionary definition of “algorithm” is:

“A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.”

That seems very similar to a technical trading strategy. You find a setup that works well for you (e.g. MACD fast line crossing the slow line from bottom-up), and you decide what you’re going to do about it (e.g. place a buy market order, with a stop loss 1% below the last support level, and close the trade when the MACD lines cross again). That’s a simple example, and it’s all numerical.

If you can identify the situations where you should open a position, and where you should close a position, then you can tell a computer to do the same thing. It’ll be faster and more accurate (assuming you told it to do the right thing!).

The benefit becomes clearer if we look at a more advanced example. Suppose you wanted to combine 5 indicators and scan a basket of 7 different assets for a trade entry. That’s a lot of information the human mind to handle. You’ll be switching back and forth between screens looking for your indicators to light up green, and telling you to get into the market.

The possibility of making a mistake is amplified when your attention is split over multiple markets.

This is when a computer shines. The capacity for a computer to handle multiple assets and indicators is much greater than that of any of us. Computers still have their limits, but even a basic personal laptop can outstrip any human when it comes to fast and accurate data analysis.

I hear some of you saying, “Yeah, but I can set alarms and signals to tell me when the market condition is right!” You can. And how do you think the alarms and signals work? They’re algorithms.

It’s one step removed from algorithmic trading, because the alarms just tell you when the market is in a certain state, they don’t handle orders or anything like that. That part is up to you. Which really is the simple part of the operation. Why not get an algorithm to do all of it? It’s cheaper than hiring an assistant.

How are they used in trading?

Photo by Thomas Kvistholt on Unsplash

Besides general automated trading, there are a few specialized uses for automated trading, including:

  • High-Frequency Trading (HFT)
  • Arbitrage
  • Scalping
  • Transaction cost reduction

HFT groups execute large volumes of transactions at high speed, hence the name, “high-frequency”. In 2008, after the collapse of Lehman Brothers, there was a big concern about liquidity in the stock market. The NYSE decided to do something about it in 2016. They introduced new incentives for market makers, enticing groups to provide liquidity in the market by offering an average rebate of $0.0019 for transacting in NYSE- and NYSE MKT-listed securities.

It doesn’t sound like a very big incentive, but if you’re making millions of trades every day, the rebates begin to add up. How could a human possibly make millions of trades a day? And millions of profitable trades at that!

They can’t.

Enter, automated trading systems. By introducing a rebate, the NYSE incentivized the use of HFTs, entities that can make trading decisions in microseconds, and are rewarded for it.

Some see it as unethical, because HFTs have a greater advantage over non-HFTs. They do, but that just means the rest of the market needs to adapt to the new players. Adapt or die. The markets are constantly changing, this is just another one of those changes. The world is becoming computerized, and there will always be people standing in the way of progress, because what’s “progress” for everyone else actually harms these people in the short-term. So it’s understandable that people would be irked by HFTs.

But progress is progress. The jobs that can be automated will be automated. We need to deal with that fact. Don’t worry, we’re not going to dive into a discussion about automation and the future of humanity today.

Let’s get back to automated trading.

Another specialised use of automated trading systems is to do arbitrage.

Arbitrage is the simultaneous buying and selling of the same asset in 2 different markets, whose prices are out of sync. For example, right now BTCUSD is trading at 7281.50 Kraken, and 7294.10 on Bitfinex. The difference is 12.60. If you can buy BTC on Kraken and sell it on Bitfinex, you can make 12.60 per BTC, no questions asked.

It’s seen as “risk-free” because you’re buying and selling the same asset, as such the prices should converge eventually. I said “should”, because this might not always be the case.

These price discrepancies might not last very long, because there are other traders out there watching prices, and hoping to take advantage of the spread too. So you need to be quick.

And what better way to trade quickly than to program a computer to do it! Arbitrage bots are seemingly simple, but become increasingly complex. There are many different problems that you wouldn’t normally encounter in other kinds of trading, such as execution speed. This becomes a problem because the price differences won’t last long before another arbitrageur capitalizes on the difference. So it’s the fastest finger first.

Some trading groups resort to “co-location”. This is where the trading company’s trading algorithm is hosted on a server in the same building as the exchanges servers, so they can be directly connected with fibre optic cable.

When many trading company’s do this, the data centre provides fair conditions for all the groups by using exactly the same length of fibre optic cable to connect each trading group’s server to the exchange server. It gets down to that level of detail, that’s how high the competition is in this space!

Scalping is another application. It involves entering trades and closing them after a short time in order to make profits from small price changes. If you watch a chart for any liquid asset, even the top 10 cryptocurrencies, you’ll see the price moving constantly. Scalpers profit from this movement.

In a similar vein to HFTs, scalpers make money from scale. If you’re making $0.10 per trade, you need a helluva lot of trades to make any significant profit. But with algorithmic scalpers, you can do just that.

Scalping demands quick decision making, something that computers are better suited to than us humans. Working on short timeframes and making short term trades is something that requires the speed and accuracy of a computer.

The short timeframes also help to limit risk exposure for scalpers, as they’re only exposed to market movements for a very short period of time. They don’t have to worry about large swings in price because they’re only in the market for a few minutes at a time.

Smaller per-trade profits are also easier to obtain. It’s more likely that the market will move 0.10 in the same direction than 1.00 in a given timeframe. This makes it easier for scalpers to make profit on every trade. These moves are more frequent too, so scalpers can make money even when the market is relatively quiet.

Some may look down on scalping as a lower form of trading, but at the end of the day it’s a way to make money in the market. Maybe you’re more suited to scalping than technical or fundamental analysis? If so, that’s great. The aim of the game is to make money, not to be the most intelligent person in the market, or even the most skilled.

The final type of automated trading that we’ll discuss here is transaction cost reduction. Algorithms are used to break large orders down into smaller ones, and then enter them into the market over time to get the best possible price.

Large orders can move the market, so large institutional investors will use automated systems to cut up their orders into bite-sized pieces that can be absorbed by the market without affecting the price too much, if at all.

It’s a less exciting use of algorithms in trading, but it’s very necessary, and it’s another example of a job that is much better done by a computer than a human.

Why would anyone use a trading algorithm?

Photo by Kevin on Unsplash

We’ve discussed some of the advantages of automated trading systems already. I want to reiterate those here and go into a little more detail.

Computers are faster than humans at processing data. They’re designed to do math. Our brains evolved to detect danger, and flee or fight it. Computers will beat us in every math competition. They’re faster and more accurate.

This allows computers to make decisions and act on them much quicker than we can. Perfect for monitoring 1 minute charts in trading, and taking action as soon as the market shows signs of making a move.

Imagine trying to monitor the 1 minute charts of even the top 5 cryptocurrencies, watching the price action of each, and monitoring signals from multiple indicators. How likely is it that you’ll be able to capitalize on every opportunity that comes your way? Not very.

It’d be a breeze for your silicon-brained friend.

Automated trading systems can be used to cheaply scale your operation as well. Imagine if you had to hire another trader or trading assistant every time you wanted to enter a new market. Your attention is limited, and there’s only so much the human brain can concentrate on at once.

If you’re trading cryptocurrencies and want to expand into forex, then you’re going to need help. Automated trading systems can provide this. If you understand the rules you trade by, and can codify your crypto strategy, then you can make an automated trading system to handle that aspect of your business. Leaving you free to focus on your foray into forex.

You can rinse and repeat this cycle as many times as you want, setting up automated systems in each market to handle your trading activities.

If you’re sick of staring at charts all day, and you don’t want to trade anymore, then you can program a system to do it for you while you focus on something more fulfilling.

We know you’ll be back though. There’s a reason you started trading, and it’ll draw you back to the market eventually.

Are there any downsides?

Photo by Jens Johnsson on Unsplash

I’ve made it seem all rosy in the world of automated trading systems, but it ain’t.

One of the major upsides of automated trading is also it’s Achille’s heel. If computers can make winning trades very quickly, they can make losing trades just as quickly. If the system starts to enter into losing positions, it’ll do so very quickly, and you might stack up substantial gains before you know what happened.

One way to mitigate this is through the use of proper risk management practices. A trading system can only do what you tell it to do, so if there’s a scenario that you haven’t thought of (it’s VERY likely that you won’t think of everything) the trading system will continue to use the rules you set even if it’ll cause you to lose money.

Risk management rules can help here. You could set stop-loss limits on each trade, e.g. close position at 5% loss, and even shutdown the trading system if the drawdown exceeds a given value. These practices can help to ensure you don’t lose your whole trading stake from a few bad trades. Because when it happens, it’ll happen faster than you can say “Long Term Capital Management”.

Automated trading systems tend to be inflexible.The computer can only do what you tell it to do, sometimes people think they’ve told it to do one thing, when they actually told it to do another, “The damn machine isn’t doing what I told it!”. But it’s not possible for the machine to do anything other than what you told it to do (I’m not talking about AI here, as that’s another kettle of fish).

So when the market changes, your algorithm might, and probably will, need to be updated.

The 2010 Flash Crash is a prime example of the dangers of automated trading.

On May 6, 2010, a trillion-dollar stock market crash started at 2:32 pm EDT, lasting about 36 minutes. Some of the major stock indices in the US, such as the S&P 500, Dow Jones Industrial Average (DJIA), and Nasdaq Composite, promptly crashed and regained their losses in quick succession.

It’s known as the “Flash Crash”. The DJIA suffered the second biggest intraday point drop in history! It lost 998.5 points within a few minutes. That’s a 9% drop! Luckily it wasn’t sustained, and the index recovered most of the losses within a few more minutes.

The crash was, in part, caused by automated trading systems, namely HFTs.

It was found that a large fundamental trading firm, Waddell & Reed Financial Inc., had entered an order to sell 75,000 E-Mini S&P contracts (~$4.1 billion worth). This was an unusually high volume, and was quickly swallowed by HFTs buying the contracts.

Just as quickly as they’d bought the contracts, the automated trading systems sold the contracts again. The Wall Street Journal quoted the official report into the incident, stating:

“‘HFTs [then] began to quickly buy and then resell contracts to each other — generating a ‘hot-potato’ volume effect as the same positions were passed rapidly back and forth.'”

While this was going on in the futures market, the effect spilled over into the equities market, probably due to arbitrageurs taking advantage of the price difference between S&P 500 stocks and the E-mini S&P contracts. Stock prices went awry, with companies such as Accenture and P&G trading at pennies or $100,000! The world had gone mad!

The debacle was ended when, as the official report states:

“At 2:45:28 p.m., trading on the E-Mini was paused for five seconds when the Chicago Mercantile Exchange (‘CME’) Stop Logic Functionality was triggered in order to prevent a cascade of further price declines. In that short period of time, sell-side pressure in the E-Mini was partly alleviated and buy-side interest increased. When trading resumed at 2:45:33 p.m., prices stabilized and shortly thereafter, the E-Mini began to recover, followed by the SPY”.

As I’ve already stated, computers can make decisions and act on them much faster than we can. They can play a big part in exacerbating market events such as this. Who could predict before-the-fact that the automated trading systems would react in this way to such an event? I doubt many people, if anyone at all.

You cannot, and should not attempt to, predict what is going to happen. Just be prepared for the general cases: the market goes up quickly, the market goes down quickly.

How can I make money from trading algorithms?

Photo by Aidan Bartos on Unsplash

In Ed Seykota’s early days, he programmed trading algorithms onto punch cards that were read by a computer! Luckily trading technology has come a long way since then. Now anyone with basic programming skills can whip up a trading algorithm.

If you have a trading system, whether that’s based on indicator signals, pure price action, or other technical analysis, you can write a short script to monitor your chosen indicators and act on them. If you don’t have programming skills, then contract out the job on a platform like UpWork.

There are a few trading platforms around that allow you to write your own trading algorithm, and integrate it with their infrastructure. You don’t need to worry about connecting to exchange APIs, how to calculate profit and loss, or even how to execute orders. These systems have solved all those problems, so you can work on the high-value aspect of your trading operation, the algorithm itself.

Some of the platforms that are available include:

Quantopian doesn’t support cryptocurrencies, but I thought I’d add it in because it’s the most advanced of all these systems. Catalyst was forked from the technology underlying Quantopian, but differs because they’re focused exclusively on cryptocurrencies. It’s the system I use now. Both are written in Python.

I haven’t tried HAASONLINE because it’s a paid service, but I thought I’d add it to show what other types of solutions are available now. And Gekko is an alternative written in Javascript. I don’t think it’s as polished as Catalyst, but it does provide some good features.

One thing Catalyst, Gekko, and TradingView have in common is backtesting. Both systems allow you to download historical price data from exchanges, and test your algorithm over a period of time in the past.

This is great for developing your algorithm and honing it. On Catalyst, depending on the pair you want to test against, you can trade from sometime in March 2015 up until yesterday, and any period in between. You can backtest as much as you like, without risking any money, until you’re happy with the results.

TradingView has a very simple scripting language called Pine, that you can use even if you have no experience in programming. It’s very straightforward, and can be your gateway into automated trading.

Be aware, excessive backtesting can cause you to overfit your strategy to the historical data. That is your algorithm may work perfectly for the price action from Jun 2017 to Dec 2017, gaining you 3,000% (woah!) but it might only work for that period of time. Market conditions are constantly changing, so you can’t rely on backtesting to give you the perfect algorithm.

A strategy I’m trying out now to hone my algorithm is to use a Monte Carlo simulator to generate random prices for the next year, then pipe those into Catalyst, and run my algorithm against that dataset. This way, I can test my algorithm against an unlimited number of possible future scenarios.

I’m not going to go into the details now, but basically I use the historical volatility to generate prices.

No need to get technical right away though. Backtesting will suffice to begin with.

Once you have a strategy that’s been tested, you should test it with a paper trader and live data, to ensure there are no problems in switching from the backtesting system to the live trading system. You don’t want a programming error to cause you to lose your whole stake in the first day!

If you’re happy that your strategy is working well with live data, then go ahead, open up trading accounts, deposit some trading capital, and start your trading bot.

There you have it, the basics of automated trading. Seems simple, eh?

Automated trading is a great tool to have in your trading toolkit, I’d say the hardest thing about it is codifying your strategy. Converting your strategy into code that a computer can interpret can be very difficult, but totally doable if you put your mind to it.

Don’t forget that the risks in discretionary trading are amplified by automated trading. Your bot can only do what you tell it to do, so if market conditions cause it to enter losing positions, it’s gonna enter losing positions, and quickly! These losses can mount up so have proper risk management systems in place:

  1. Set a max drawdown limit that’ll kill the bot if it’s triggered
  2. Use stop losses on EVERY TRADE

There’s a lot of work required upfront when developing a system, but the time you’ll save in the long run is invaluable. That time can be spent on reviewing the performance of your trading bot, designing improvements to your system, building more bots to boost your profits, or just kicking back with an Old Fashioned on a beach in Barbados. Do whatever you want, you earned it.

You should read these because, in trading, information is everything:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.