Algorithmic crypto trading is automated, emotionless and is able to open and close trades faster than you can say “HODL”.
Thousands of these crypto trading bots are lurking deep in the exchange order books searching for lucrative trading opportunities. They range in complexity from a simple single strategy script to multifaceted and complex trading engines.
They are also becoming much more popular. As the crypto markets get flooded with new entrants, smart traders have to resort to new methods of getting an edge over their competitors.
But, are crypto trading algorithms profitable and can you get involved?
In this post, we will give you everything that you need to know about algorithmic trading.
Page Contents 👉
- 1 What is a Trading Algorithm?
- 2 How Do Trading Algorithms Work?
- 3 Trend Following
- 4 Reversion to the Mean
- 5 Arbitrage Trades
- 6 Order Chasing Bots
- 7 How To Develop An Algorithm
- 8 A Note on Open Source Bots
- 9 Quant Funds and HFT Incoming
- 10 Conclusion
What is a Trading Algorithm?
Simply put, algorithmic trading is the use of computer programs and systems to trade markets based on predefined strategies in an automated fashion. In the retail markets, they are sometimes referred to as robots or “bots”.
The term could be used to refer to anything from a simple trading script that you developed on your home computer to the multimillion dollar systems that are used by HFT Quant Funds on Wall Street.
There are a number of advantages that these algorithms have over human traders.
The first and most obvious of them is that they are able to run perpetually. When human traders have call it day, these robots can keep running as long as the cryptocurrency markets are open. Given that these markets are open 24/7/365, so can the bots operate.
Image Source: MQL5
Another advantage of these trading bots is the speed with which they are able to place the trades. These bots are usually run-on high-performance servers that are able to open and close trades in the blink of an eye.
However, the most important benefit of a algorithm is that it has no emotion.
These systems are governed entirely by code. There is no emotional component when these scripts place their trades. They merely process the numbers and execute the trade irrespective of how you may feel.
Indeed, feelings of fear and greed are often some of the direct causes for large trading losses. A trader will divert from a tried and tested strategy merely because of how they feel.
So bots are clearly an effective tool in a saturated market.
How Do Trading Algorithms Work?
If you have a strategy that relies purely on crypto asset price relations, then it is possible to develop an algorithm for it. Indeed, there are numerous strategies that can be employed with algo trading (we will cover below).
They are usually coded in well known programming languages including Python, Nodejs, R, C++. These will then be run on dedicated machines that will connect to an exchange API and use the price feeds as the inputs to the model. The outputs will be orders.
Some of the Programming Languages use for Algorithms
In order for them to function and be profitable, you need to have three things in the market. These are the following:
- Strong Liquidity: You need to have liquidity in the order books if you are going to have a bot placing trades at desired levels. It does not help if you have wide bid/ask spreads and the trading algorithm has massive order slippage. This will work havoc on any automated system and perhaps explains why bots do not operate on low volume low market cap altcoins
- Open Access: This is related to how the bot itself can access the exchange’s order books. Although most cryptocurrency exchanges these days have API functionality, some of have limitations. The more limitations that an API places on your access to information, the less effective your trading algorithm is.
- Nascent Market: This is a catch 22 of the algorithmic trading conundrum. Essentially, the less competition that you have from competing trading algorithms, the greater your profitability. As you get more competition from other operators then you will have to refine it to make your bot either smarter or faster. This is also more relevant when it comes to executing strategies that are related to arbitrage (mispricings).
In the cryptocurrnecy markets, we currently have all three of the right ingredients to operate these algorithms.
Across the top 10 market cap cryptocurrencies, we seem to have strong liquidity. We also have open access from a number of different exchanges with pretty robust API systems. These include those exchanges that offer physical trading as well as those that offer derivatives such as the Bitmex Futures.
Yes, the markets are becoming more saturated and more competitive but nowhere near as much as the Equity and futures markets are. This could of course change as more institutions start entering the market. They could be followed by a range of high frequency trading firms and quantitative Hedge funds.
So crypto algo trading is still profitable, but what kind of strategies can you develop?
For those traders who make use of technical analsysis trading strategies, then these are probably quite familiar to you. Whatever rules that you use in order to inform your daily trades, you can code into a cryptocurrency algorithm.
This is usually based on the notion that markets have momentum and you want to be on top of that momentum. One of the most well known technical indicators are those of trends. There are numerous technical indicators that try to map trends.
For example, one of the most well known of these are Moving Average (MA) Cross Overs. These occur when a “faster” and shorter term MA indicator crosses over the longer term or “slow” indicator.
In the below image, we have an example of a classical 50-day MA crossover of the 200 day MA indicator. In this case, the crossover is an indication of a bearish trend and Bitcoin (BTC) should be shorted.
Moving Average Crossover on BTCUSD. Image via Tradingview
The opposite will occur if the fast indicator crosses over the slow indicator from the bottom. In this case, you should go long Bitcoin. This is usually one of the simplest indicators and traders will usually combine it with a range of others.
You could develop a simple trading algorithm that will execute the trade for you. It should have the functionality to also place stop losses and stop limit orders when the execution order is given. Most bots will usually incorporate a range of different TA indicators in their trading tool box.
Reversion to the Mean
While markets are able to follow a particular trend for a period of time, extreme and unusual movements are usually an indication of a potential reversion to a longer-term mean.
In other words, if there is a movement in the price of an asset that takes it to levels that make it look extreme by historical standards, then there is strong chance that it is likely to come back or “revert”.
Mean reversion strategies will take a look at historical distribution and then place the current movement in context of that. There are also a range of different mean reversion strategies that a bot can employ. Let us take a look at two of them.
Standard Deviation Reversion
For those of you that are familiar with statistics, you will have heard of the concept of a standard deviation. This is the notion of an average movement away from statistical mean and it is used to model abnormalities in data.
One of the most important data points from a trading perspective is that of 2 standard deviations. These are used in order to model the Bollinger Bands around the moving average of a trading pair.
If you are to develop a trading strategy that is based on mean reversion, you could use bollinger band crossovers as an indication that an asset is oversold / overbought and hence is likely to revert.
For example, in the below chart we have the price of Bitcoin Cash (BCH) in Bitcoin and we have modeled the Bollinger Bands (BB) on the 20 day MA. As you can see, there were two points when the price crossed below the bottom BB.
Mean Reversion on BCH/BTC away from the Bollinger Bands. Image via Tradingview
This was an indication that the price of the asset was oversold and hence is likely to revert soon. You could create an algorithm that will enter a trade contingent on this condition. This would be a short sale on the flip side when the price of the asset crossed the upper band.
Of course, this is the most basic of Bollinger Band mean reversion strategies. You could use different time components or a combination of a few. You could also incorporate it with greater standard deviations.
That is the beauty of a trading algorithm, you can use numerous inputs that will determine trade action much more effectively than a human trader ever could.
Mean reversion trading is not only reserved to one asset but can also be used when trading the spread between two different assets.
The notion is that if two assets have been trading in near lockstep in the past then if there is a reversion away in that historical relationship then it means that the two assets are likely to revert back.
You will then sell the asset that is “overpriced” and you will buy the under-priced one. In this case, if the prices do revert, you will make a profit. Moreover, you are less exposed to the general market moves as you are long one asset and short the other.
It is important though that these assets have the same systematic exposure to the broader market. For example, common pairs trading strategies use two stocks in the same industry such as Apple and Microsoft.
In the case of cryptocurrency trading, you could easily trade the historical relationship between two different coins. They will have a pretty high correlation with general crypto market movements which means that you are quite hedged against adverse market moves.
Reversion to the Mean in Pairs Trading, ZEC to XMR. Image via Tradingview
As you can see, there were two occasions when the ratio was beyond the 2 standard deviation. This means that it could eventually revert and you will short ZEC and buy XMR hoping that the latter will increase in price and the former will decrease.
Here, you will use inputs that are similar to those that we mentioned above. You could take a look at the Bollinger Bands and use that as a sign that the spread between the prices has increased / decrease beyond historically justifiable numbers.
Except, in this case the crypto trading algorithm will put out orders for more than one cryptocurrency. It will output the specific buy / sell orders for XMR and ZEC separately.
This is perhaps one of the most favorable trading opportunities that exist for crypto trading algorithms. With arbitrage trading, you are trying to take advantage of market mispricings and earn a risk free profit.
There are numerous arbitrage opportunities in the markets currently which exist across exchanges and even within them. We won’t go into all of the strategies as we have covered it extensively in our piece on cryptocurrency arbitrage.
Arbitrage opportunities are those trades that exist precisely because there are not that many people who are trying to take advantage of it. There is low competition from other trading algorithms which makes it more profitable for those that are first to the market.
Similarly, to take advantage of these opportunities you need to be quick. They often only exist for a few seconds before a market realises that there is a mispricing and closes the gap.
In the cryptocurrency markets, the arbitrage trades that are usually the most profitable are those that trade the differences in price between coins on numerous exchanges. For example, they could trade mispricing on the value of Ripple on BitFinex and the Binance exchange.
This will require the bot developer to have an account with both exchanges and to link the orders from the algorithm up to their API systems.
There are also bots that are able to take advantage of mispricings on an exchange itself. For example, there is this bot called “Agent Smith” which was able to make quite a bit of money during the bull market as it traded mispricings on the Poloniex.
Below is an example of a potential triangular arbitrage trade that an algorithm could enter. As you can see, there is a mispricing in the price of Litecoin (LTC), Bitcoin (BTC) and Ethereum (ETH) on the Kraken Exchange.
Example of Potential arbitrage trades on Pair Mispricings
What is likely to happen in this case is that the mispricing will only exist for a few seconds and those bots that are able to spot it and place the trades will reap the rewards. These algorithms will scan the Kraken orderbooks by the millisecond in order identify that slight gain.
Order Chasing Bots
Order chasing is the action of placing trades in the anticipation of order flow that is about to come from much larger buyers / sellers (institutions).
It is important to point out though that order chasing based on insider information is illegal (termed “front running”). In other words, if you are a broker who knows that your client is about to make a large order and you enter trades before them, you are trading on insider info and could get a visit from the SEC.
However, if you have an algorithm that is able to determine order flow before the other participants based on publicly available information then it is fair game. In this case you need your algorithm to be incredibly fast in order to adapt to potentially market moving news before your competitor can.
This is actually the strategy that is used by a number of highly sophisticated high frequency trading companies on wall street. They will try to read order flow before the large institutions are able to.
Currently, there are not too many institutions in the cryptocurrency markets and those that do participate will usually opt to make trades in the OTC markets (larger block purchases). However, you can still make a decent return from order chasing large retail demand.
For example, during the madness of the 2017 bull run, developers were coding algorithms that would buy coins that were being tweeted out by John McAfee in his “coin of the day”. They would scan his tweets for Crypto tickers and then place orders in anticipation of the demand.
McAfee Pump!!! There we go! Dead coin gained a new life pic.twitter.com/gTGfIExg31
— dimsome.eth 🦇 🔊 (@dimsomedim) December 23, 2017
These Python bots have even been released as open source on Github. For example, there is this one by Dimension Software and this one by drigg3r. These probably will not serve much of a purpose now as McAfee has ended the practice long ago. Indeed, many perceived these actions as pump-and-dumps which are also illegal.
Even though this example is questionable, it does illustrate how developers were using potential order flow in order to buy before all the other participants could get in.
How To Develop An Algorithm
While the technicals of how to code a crypto trading algorithm are beyond the scope of this article, there are a number of generally accepted steps one should follow when developing bots.
Before you can actually start developing a trading algorithm, you have to have an idea of the type of strategies you want it to employ. Algorithms start as your ideas which are then formulated into code and subsequently defined.
Here are some of the loose steps that you can take when you are developing your trading algorithm.
1. Formulate Your Strategies
You may have an idea about a particular strategy that you want the bot to follow. This could either be a simple hypothesis based on movements in the markets that you have observed and want to exploit.
Alternatively, it could a range of strategies that you have used in your technical trading endeavors. You could have placed these trades based on visual levels whici now need to be formulated into defined decision-making processes.
2. Code it Up
This is probably one of the most involved processes and requires you to understand programming languages such as Python, Nodejs, C++ or Java.
This is the stage where you turn that decision-making process mentioned in step 1 into defined code. In the simplest of cases this is usually a collection of if-then statements that will take actions based on defined conditions.
3. Back-testing on Historic Data
This is a really important step that helps you test your hypothesis over an extended period of past data. You can try it out on a range of different markets over numerous different time frames.
Backtesting a Simple Mean Reversion Strategy. Source: Quantopian
This is also generally quite an easy step to perform as you have a great deal of data to work with.
4. Refine Algorithm
The prime reason that you will want to do back testing is to iterate and improve your algorithm. You will have verifiable return results from the back-testing that will allow you to assess the profitability.
You can then adjust the parameters that you are using such as look-back and moving average periods as well as the kinds of assets that you can trade and their relative profitability.
Once you have the most well optimised strategy, you can then move onto testing your algorithm in real time.
5. Minimal Live Account
Order sizes can easily be scaled with the trading algorithm and there is no reason to jump into the markets with large orders before it has been adequately tested. Therefore, you will want to start with a small amount of initial capital with lower order sizes.
You will connect your trading bot to the API of an exchange and allow it to run. This stage must be carefully monitored as we all know that current returns can be widely different to past returns when statistical relationships break down.
Moreover, when you are trading live you have to execute orders which could face latency. The slower speed of the execution could also impact on the performance that you observed in the back testing phase.
Examples of Maximum Latency for Particular Algorithmic Strategies. Source: Quantinsti
You will use this period of limited live testing to decide whether to advance your trading sizes or whether to further refine the code.
7. Upsize and Monitor
If you are more comfortable with the returns of your bot then you can increase the trade sizes. This is not entirely straightforward as larger order sizes on more illiquid cryptocurrencies could hamper the model performance.
Hence, it is important to only scale in increments and constantly monitor the impact that is having on the returns compared to what you expected.
You also want to make sure that you have strong risk management protocols in place. Often bots can perform in unexpected ways and trading algorithms can go haywire. The last thing that you want is for your system to place wayward trades that could liquidate you.
A Note on Open Source Bots
There is a great deal of open source code that can be used to develop and run crypto trading algorithms. These are fine to use as long as the code is indeed open and you can audit it.
There are a whole host of fraudulent crypto trading robots that are often promoted as an automated and simple way for traders to make money. These are often nothing but scam products that will either steal your private keys or take you to an illegitimate broker.
Example of a Scam Bot Promoted Online
For example, you have Bitcoin Trader which is sold under the false pretext of making profit for their users. The same robot has been involved with fake advertising which claimed that it was endorsed by the Dragon’s Den Peter Jones on twitter.
Another more user friendly alternative is to develop programmitic trading scripts on the MetaTrader platforms. MT4 and MT5 are well known platforms used to trade CFDs (Contracts For Difference) which are another derivative product. We won’t go into CFDs here but for more information you can read this overview.
Quant Funds and HFT Incoming
While the current crypto trading algorithms may seem advanced, they are nothing compared to the systems that are at the disposal of wall street Quant funds and High Frequency Trading (HFT) shops.
As the markets become more accommodating to institutional investors, these sophisticated trading operations are likely to follow. Indeed, there are indications that a number of HFT firms have started trading in the crypto markets.
For example, it has recently been reported that prop trading firms including DRW, Jump Trading, TransMarket and XR Trading are involved in cryptocurerncy markets.
Traders Discussing Strategies at DRW’s Cryptocurrency Unit. Source: DRW
These firms are committing extensive resources and skills to developing cryptocurrency trading algorithms that operate in mere milliseconds. They set up their trading servers in dedicated co-location data centres near those of the exchanges.
However, is this a good or a bad thing for cryptocurrencies?
Well, these HFT firms have indeed attracted a great deal of ire from some for the impact that they have had on the equity markets. For example, the 2010 flash crash of the Dow was widely blamed on HFT firms. They have also been negatively portrayed in Michael Lewis’ Flash Boys book.
Yet, there are a number of people who view the HFT firms providing many benefits to the ecosystem. For one they are able to provide ample liquidity and effective execution for the large institutions.
Some also claim that they help to make the markets more efficient by eliminating numerous pricing inefficiencies that would otherwise exist.
Whatever your view of HFT firms and quantitative funds, cryptocurrency markets seem to be a natural home for them. As soon as there is more clarity from regulators around the custodial and clearing aspect of crypto, there could be a flood of other firms and funds which enter.
Unfortunately for the current crypto algo traders who rely on arbitrage opportunities, the entrance of these funds could mean an elimination of any risk-free trades that existed. However, they could shift to other more established strategies.
While cryptocurrency algo trading has become more competitive in recent months, there are still interesting opportunities for retail traders to take advantage of.
Even though the arbitrage opportunities are being gobbled up by the HFT firms, you can still develop your bot to trade on technical indicators and well-established trading patterns.
Indeed, if there is a strategy that you have been using that has worked well for you, there is no reason why you should not be working on your own algorithm. If you are going to be using open source software, make sure it is safe and not run by scammers.
Of course, as with trading manually, you have to take a concerted effort to appropriately manage your risk. Algorithms work well until that one day they don’t work. That one day could completely eliminate all your gains.
Yet, as long as you don’t risk more than you can lose and you have appropriate kill switches, then you should be well protected.
Featured Image via Fotolia