The Benefits of Algorithmic Trading Strategies
Trading your own money by hand comes with numerous psychological pitfalls: oversizing, overtrading, revenge trading, and hope trading. Instead of deceiving yourself with selection bias and impulsive reactions, consider letting algorithms work for you.
Algorithmic trading refers to the process of executing trade orders using automated pre-programmed instructions. Algorithmic trading systems can execute trades at high speeds and frequencies, enabling traders to capitalize on market opportunities efficiently. A trading robot has 24/7 availability and ensures that trading opportunities are captured even in volatile market conditions or across global time zones.
If you want to capitalize on automated trading and reduce human error with computer algorithms, you need a good strategy and foundation. In this article you will be introduced to three effective approaches used by quantitative traders in hedgefonds.
How to Backtest Algo Strategies
A good strategy has to be tested on historical data. This data-driven approach allows for systematic risk management and portfolio optimization, ultimately maximizing returns while minimizing downside risk.
There’s two approaches to backtesting your strategy. The first way is to code strategies by yourself with Python or mql4 and test them with said languages. It is more work and requires programming skills. The second approach is to use no-code platforms, which offer a lot of shortcuts to build a fully automated strategy for a small price to be paid.
Let’s say you have coding skills. Here’s what you will need:
- Data: You need historical OHLCV (Open, High, Low, Close, Volume) or even Tickdata to make a valid backtest. The more data the better. When backtesting forex trading strategies you can start with free data from histdata. Free data is often limited. backtestmarket Is a service that offers data in packages for a reosanable price. They also have commodities and indices.
- Backtesting Library: The backtesting library can be easily installed with pip. It includes a lot of indicators and best practices. An alternative is to use the meta quotes language mq4 that can be used in Metatrader 4 + 5. Metatrader has a built-in backtester. However, the data is often limited. If you want to up your backtesting game in Metatrader use the Quant Data Manger by StrategyQuant.
- Connection to a broker: You need to execute your backtested strategy on the live market. With python you have to write functions that execute orders with a client like the ByBit Client. In Metatrader, open the navigator tab. Then you can drag and drop an Expert Advisor (a compiled mq4 file) on a chart with your connected broker.
- Hosting: You don’t want to run the algorithmic trading strategy on your local machine, you need to host them. For python I can recommend pythonanywhere with its always-on-tasks. Tip: if you need an IP from the EU use the EU Version of pythonanywhere. For a metatrader strategy you need a virtual private server with windows. You can also decide for hosting with metaquotes itself, it’s platform integrated and therefore comfortable. A cheaper alternative is Cheapforex-VPS.
You will probably think, that’s a lot of coding work, but don’t worry there is very established products on the market that help optimize and build strategies, even deploy them directly. Here’s a list of algorithmic trading software platforms that make robot trading simple and require no code if you choose so:
These platforms suit forex algorithmic trading, as well as providing an array of algorithmic trading examples, that you can build your ideas from.
Also you will not have to worry about historical datasets anymore because they are included. Choose one that suits your preferred markets you want to trade on, the price you’re willing to pay and make sure the deployment can connect to your broker.
Create Algos with Freelance Services
If you have an idea but don’t want the hassle of backtesting and optimizing your strategy you can use a freelance service like fiverr or the mql4 freelance marketplace. You will need to have a clear vision on what you want. The best way to approach this is to write down your trading idea in great detail. Think about stoploss distances, position sizing, entry conditions, exit conditions, timeframes and trade management. Don’t have unrealistic expectations.
Concrete Strategies for Algorithmic Trading
At this point, you should have reached a decision regarding how you intend to backtest. You may have considered whether to delve into coding or utilize existing platforms. Now, the crucial choice lies in selecting the strategy itself.
The majority of automated trading strategies can be categorized into two main types: Momentum Trading and Mean Reversion. Additionally you can use statistical arbitrage in the form of pairs trading, which is a subtype of mean reversion trading, but with two correlated assets. These strategies can be used for day trading, swing trading and position trading.
While there are indeed a plethora of other trading strategies such as Index re-balancing or Machine learning AI, they often fall under the umbrella of these main types of trading trading strategies. Also, some of these strategies might not be as suitable for retail forex traders due to various reasons:
High-frequency arbitrage (HFT): High-frequency trading strategies require ultra-fast execution speeds and low-latency connections to the market, which may not be feasible for retail traders due to the high costs and infrastructure requirements.
Index re-balancing: Index rebalancing strategies typically involve large-scale transactions and are related to ETFs and not forex and commodities trading. Re-balancing long/short portfolios is something that is better done manually, because of the long time-horizons it aims for.
Black Swan Catching: Strategies or black-box trading aimed at catching black swan events or extreme market movements are inherently risky and difficult to execute, as they rely on predicting rare and unpredictable events that can lead to significant losses if miscalculated.
Inverse Volatility: Trading volatility-related products or strategies requires a deep understanding of derivatives markets and may involve complex strategies and instruments that are not suitable for inexperienced traders and requires access to options.
While these strategies may offer potential opportunities for experienced institutional traders with access to advanced technology and resources, they may not be practical or suitable for retail traders, such as forex traders, due to factors such as complexity, risk, or infrastructure requirements. Therefore, momentum trading, mean reversion trading and statistical arbitrage with pairs trading remain the best algorithmic trading strategies for retail traders in the forex market and other asset classes available.
Let’s get into three trading strategies you can use, that are robust and simple and will always be one of the best algorithmic strategys you can backtest and deploy in your own account:
Strategy #1: The Momentum Trading Strategy
Momentum Trading strategies operate on the premise that prices follow on the price direction in the recent past. You can use indicators like the 200 Simple Moving Average to define the trend direction and then take entries out of a correction. A correction signal could be the RSI crossing below 30 in an upwards trend. The risk-reward ratio should be over 1:2 to account against the times you are stopped out. It’s enough when about 30% of your trades are profitable, because the risk-reward ratio carries you through potential intermediate losses.
Dataset: Historical Price ETH/USD 15-Minute Data from 2023
Entry Condition: Exponential Moving Average 20 > Exponential Moving Average 20 last candle (short vice versa)
Stoploss: Average True Range 14
Exit Condition: 4 red candles (long) 4 green candles (short)
Strategy #2: The Mean Reversion Trading Strategy
Mean Reversion strategies build on the concept that asset prices tend to revert to their historical mean or average like a 20 Simple Moving Average. The strategies job is to find overbought and oversold conditions for buying or selling the asset, with the help of indicators like RSI or Stochastic Oscillator. You will have a high hit rate of about 50% or above, but on the other side the risk-reward ratio will be lesser than 1:2. Exits should be made when the price returns to it’s average or below the average, for example when the 20 Simple Moving Average is crossed.
Dataset: Historical Price ETH/USD 15-Minute Data from 2023
Entry Condition: RSI 14 > 70 and distance High – Exponential Moving Average 20 > Average True Range 14 x 2 (long), RSI 14 < 30 and distance Low – Exponential Moving Average 20 > Average True Range 14 x 2 (short)
Stoploss: Average True Range 14 x 4
Exit Condition: Close > Exponential Moving Average 20 (vice versa short)
Strategy #3: Pairs Trading
Pairs trading involves trading two related assets simultaneously, aiming to profit from their relative price movements. The strategy relies on the concept of co-integration, where the prices of the assets move together over time. You will have to take positions based on the historical relationship between the assets, taking a long position in one and a short position in the other.
In pairs trading, the spread between the prices of the two assets is monitored. This spread is standardized using the z-score, which measures how many standard deviations the spread is from its historical mean. When the spread deviates significantly from its mean, traders may take positions expecting it to revert back.
For example, in trading EUR/USD and AUD/USD, if historically these two currency pairs move together, a you might take a long position in EUR/USD and a short position in AUD/USD if the spread between their prices widens beyond its usual range. You would then close their positions when the spread narrows back to its historical mean, capturing profit from the convergence.
Dataset: Historical Price EUR/USD & AUD/USD 15-Minute Data from 2023
Entry Condition: Z-Score crosses 1 from below: Long EUR/USD Short AUD/USD, vice versa
Stoploss: Average True Range 14 x 2
Exit Condition: Z-Score crosses 0
Summary: All of the strategies offer unique risk-reward profiles and statistics and you will have profitable algorithmic strategies at hand, that can identify trading opportunities for you, while you sleep. They work in different market conditions and that’s why it’s a good approach to combine these strategies to increase robustness. Think about it: When one strategy performs bad, the other is performing well, thus reducing the drawdown of the overall equity curve.
Let’s compare the strategy’s stats:
Strategy #1 | Strategy #2 | Strategy #3 | |
Profit | 41.21% | 13.31% | 4.07% |
Trades | 2661 | 1123 | 500 |
Hitrate | 30.25% | 46.04% | 60.02% |
Average Loss | 0.67% | 0.13% | 0.35% |
Average Risk/Reward | 2.45 | 1.36 | 0.7 |
Profit Factor | 1.06 | 1.16 | 1.06 |
Biggest Rel. DD | 40.43% | 5.31% | 6.73% |
Gain/DD Ratio | 1.02 | 2.51 | 0.6 |
While Strategy #2 had less returns and fewer trades, it has a btter profit factor and therefore a better expectancy. Because the average loss of 0.13% and the biggest relative drawdown of strategy #2 is 8x less than strategy #1, you could increase the risk by 8x and make about 104% return.
Pairs Trading, strategy #3, has the same profit factor as strategy #1, however the amount of trades it takes is less and therefore the overall profit goes down. You also have to take into account how many trades a system can take within a year.
You can’t say for sure if the following year’s returns will stay the same, because a few outlier trades can make up a big part of the profits. The magic lies in trading market-specific strategies and multiple strategies that complement each other and in letting the rule of big numbers play out and catch the whole market’s opportunities within a year.
The profit percentage is not everything, it’s also important to evaluate how stable the equity curve looks. If you need to master a prop firm challenge for example, it’s best to choose strategies with high hitrates aka more stable returns.
Costs When Executing Algorithmic Trading Live
Allthough the percentages sound high, there’s another point to consider: Costs.
In the backtest there’s a 2% commission added to the trade. However in real conditions the following costs have to be added and forward tested:
- Spread
- Commissions
- Swap
- Slippage
In ETHUSD the costs might be higher than 2% in relation to the stoploss distance, depending on the exchange.
What are financial instruments with low costs? EUR/USD, GBP/USD, Dax40, Sp500, CrudeOil – these are one of the most popular markets with a tight spread. You can trade them with trading robots in low timeframes like M15. Other markets such as CAD/NZD or other exotic pairs, altcoins and rare metals like platinum – it’s strongly advised to trade higher timeframes like H4 and D1 to avoid the high costs of opening and closing a trade.
Disadvantages of Algorithmic Trading
While algo trader enjoy several advantages, algorithmic trading also comes with its own set of disadvantages:
Technical Failures: One of the most significant disadvantages of algorithmic trading is the risk of technical failures. Errors in the algorithm’s code, connectivity issues, or system glitches can lead to substantial financial losses within a very short timeframe.
Over-Reliance on Technology: Algorithmic trading heavily relies on technology. As a result, traders might become overly dependent on automated systems, reducing their ability to make independent decisions and potentially increasing vulnerability to market disruptions.
Market Risks: Algorithms are designed based on historical data and market conditions. However, markets can behave unpredictably, especially during times of extreme volatility or unprecedented events. Algorithms may fail to adapt quickly to such circumstances, resulting in losses.
Lack of Human Oversight: Automated trading systems lack human judgment and intuition. While algorithms are programmed to follow predefined rules, they may not always account for qualitative factors or unforeseen events that could impact trading decisions.
Disconnect from Fundamentals: Some critics argue that algorithmic trading can lead to a disconnect from fundamental analysis and long-term investing principles. By focusing on short-term price movements and technical indicators, algorithmic traders may overlook underlying factors driving asset values over the long term.
While algorithmic trading offers various benefits such as increased efficiency and passiveness, it’s essential for you to be aware of these disadvantages. At least for the last part there’s something you can do to make your trading robots perform better overall:
Improving Basic Trading Bots With Fundamentals
The three examples of profitable algorithmic trading conditions are very solid and time-tested. However, if you are looking for ways to improve your strategy, you sould do what the professionals do and use fundamental analysis on top of executing algorithms to manage the trade for you. In fundamental analysis it’s all about predicting longer-term market moves of about 3-6 months. Based on the prediction of the fundamental analysis you can change the parameters for your algorithms to adapt to market conditions. Here’s some examples:
- The fundamental analysis predicts no change in asset prices: it makes more sense to deploy a mean reversion type strategy. Reduce the risk of your momentum strategies.
- A fundamental bullish market is predicted: Reduce risk in the mean reversion algos and set your momentum algos to a bullish bias.
- A fundamental bearish market is predicted: Reduce risk in the mean reversion algos and set your momentum algos to a bearish bias.
Fundamental analysis is a statisitcal method of bringing actual economic publications in context with its historical performances. You could for example take the Non Farm Payrolls and make a prediction based on the rolling average of the last 4 values and compare it to the returns of the stock market the next 3 months. Other key fundamental indicators are:
- Unemployment Rate
- Central Bank Interest Rates
- M1, M2 Money Supply
- Consumer Price Index
- Outstanding Home Sales
Making sense of the economic data available to you and deploying well backtested strategies in an algorithmic way will allow you to finish prop trading challenges as well as improving your wealth exponentially over time.
Managing your Trading Robots
If you go fully automated it’s also important to carefully monitor your running systems and set an overall drawdown stop for each strategy in each market. To reduce overoptimized systems, make sure you use paper trading to effectively forward test your strategies. If the strategy runs error free and profitable for 3 months on paper, it’s ready to hit the real markets.
With forward testing on paper and setting a drawdown stop, you can recycle ideas and algorithms from time to time to not let one strategy take a toll on your equity curve. Set this limit high, because algo strategies need some time to pan out. Your expectation horizon should be set to at least 1 year. You can’t really judge a trading system performance already after 1 months of trading for you. But it’s always relaxing to know you have computer algorithms to execute your trading activities instead of being prone to human error.