Subscribe to the newsletter!
Subscribing you will be able to read a weekly summary with the new posts and updates.
We'll never share your data with anyone else.

Designing Trend Following Strategies

Posted by Daniel Cano

Edited on May 15, 2024, 6:15 p.m.



What is Trend Following?

Trend following is an investment approach based on the idea that financial assets tend to move in established directions over certain periods of time. In other words, this strategy seeks to capitalize on market trends, whether upward or downward, instead of trying to predict the market's future direction. Once a trend, either bullish or bearish, is identified, positions are usually opened in the direction of the dominant trend and those positions are held until the trend begins to reverse, at which point new opportunities will be sought. Trend following strategy can be applied to various financial markets such as stocks, currencies, commodities, and bonds, and can be adapted to different investment time horizons, from intraday trading to long-term investments. However, it is important to note that no investment strategy is infallible, and trend following may have its weaknesses, such as the occurrence of false signals.

Trend Following systems

Trend following has its origins in technical analysis, an approach dating back to at least the 19th century when market traders began studying price patterns and market movements to identify investment opportunities. However, it was in the 20th century when trend following began to take shape as a systematic and quantifiable strategy. During the 1970s, it experienced significant growth, especially in futures and commodities markets. Investors began employing rule-based strategies to capitalize on long-term trends in these markets, leading to the popularization of systematic and quantitative approaches to trend following. In the 1980s, thanks to the work of several hedge fund managers and famous traders employing strategies based on this technique, it became even more popular. These investors achieved significant returns using these strategies during periods of market volatility, which attracted public attention and contributed to the spread of these strategies among a wide audience of investors. With the advancement of technology and computing in recent decades, trend following has further evolved. Investors now use sophisticated algorithms and quantitative models to identify and capitalize on trends in financial markets. Today, trend-following strategies are an integral part of the global investment landscape and continue to be employed by a wide variety of investors in different markets and asset classes. Their history of evolution and popularization reflects their importance and their ability to generate consistent returns in various market environments.

Characteristics

The main characteristics of this type of strategy are a low probability of success and a high profit-to-risk ratio. This translates into long periods of losses offset by few trades with large profits. Not everyone is capable of enduring such periods, and it will require a lot of discipline not to be swayed by emotions. This is the main reason why many adherents to this type of strategy have opted for systematic trading.

It is worth noting that there are two types of strategy, discrete and continuous. The former consists of single entries and exits, with each trade managed separately. This type of strategy is only exposed to the market during periods when there are signals. In continuous strategies, for a single trade, there can be multiple entries and multiple exits. These are strategies that are usually exposed to the market most of the time. The main difference between them is signal generation. In the first, a signal is sought when an event occurs, such as the breakout of a resistance level. Meanwhile, in the second, the aim is to expose oneself to the market proportionally to a signal, for example, the difference between the price and its moving average, so that the greater the positive distance, the larger the long position, and the greater the negative distance, the larger the short position.

Designing a discrete trend-following strategy.

1. Breakout

The first step is to define the moment when a trend begins. The most common practice is to define a "breakout," which refers to an event where the price of a financial asset breaks or surpasses an important resistance level or a significant support level on the price chart.

In this example, we will use a strategy based on the Donchian Channel. This indicator calculates the highest and lowest price during the last n periods. The entry rule will be the breakout of the channel. When the high of the candle exceeds or equals (technically cannot exceed because the channel updates with the highest prices) the upper channel line, a long position will be entered, while if it breaks below the lower channel line, a short position will be entered. Often, this second type of entry is ignored, only taking long (bullish) positions.

2. Confirmation

It is important to note that breakouts can be false signals, especially in sideways markets or during periods of low liquidity. Therefore, additional confirmations are usually used, such as trading volume or other technical indicators, to validate a breakout before making trading decisions based on it.

For this example, we will look for the closing price exchange rate to be between two values. This is because if the price does not change much, it may be that the variation does not have enough strength to create a trend, and if, on the contrary, it changes very quickly, it will attract the attention of reversal traders who will look to short sell.

3. Regime Filter

Trend-following strategies tend to work better in favorable market regimes, especially when their time horizon is longer. This is due to the clearer trends, lower market noise, higher market participation, investor trend following, and lower volatility, creating a conducive environment for identifying and exploiting market trends. If this type of strategy is applied to a highly correlated asset universe, it is advisable to develop a method for filtering out unfavorable market regimes. When the asset universe is poorly correlated, there may be different regimes for different assets, so filtering it out could be counterproductive.

4. Dynamic Stop Loss

Trend followers often try to exploit trends for as long as possible to maximize their gains. Instead of defining profit-taking prices, they often prefer to define a maximum price retracement after which they will exit. The "Stop Loss" (SL) is the mechanism used to define the maximum loss of a trade, which is an order that, when reached by the price, closes the position. The fact that it is dynamic refers to the order moving with price fluctuations. There are different ways to move it; the most common is to move the order proportionally to the price only when it moves in a favorable direction for the trade.

In the proposed case, a Donchian Channel with a period shorter than that used for entries will be employed. Thus, a long position will be closed when the price reaches the lower line of the channel, and vice versa for short positions.

5. Signal Classification

 

When it comes to trading multiple assets, there will be periods of time when too many signals are generated and not all of them can be capitalized on due to capital constraints. A system will need to be employed to classify signals based on their quality. In the case of continuous strategies, this is done naturally by how positions are calculated, but in the case of discrete strategies, a specific way of classifying signals will need to be defined.

6. Liquidity Filter

As the available capital for trading increases, new risks for trading arise. One of them is trading assets that do not have enough liquidity to enter and exit smoothly, which is exacerbated by shorter time horizons due to the importance of entry price. Volume limits are often defined to avoid this problem, but this is a partial solution. No matter how high the trading volume of an asset is, if the position size is also high due to the low price, there may be a situation where one cannot enter or exit at the desired price. The correct solution would be to set limits for the monetary volume based on the desired position. An example would be that the position represents only 1% of the average daily volume calculated over the last month multiplied by the price of the asset. This does not prevent situations of illiquidity, but it does decrease their probability.

7. Backtest and Stress Test

After defining all the parameters above, a "backtest" should be performed to see if the strategy would have been profitable. A backtest is conducted to avoid wasting time and money checking the profitability of the strategy; obviously, the actual performance will be different from that of the backtest, but one can get an idea from it. Additionally, it is advisable to carry out a stress test, in which the parameters of the strategy will be modified to see if it remains profitable or not. If there is a significant difference in the results obtained between tests, it means that the strategy is not very robust, so the backtest is less reliable, and more caution should be taken with its implementation in a real environment. Robustness often can be reason enough to discard the strategy.

In the proposed example, the backtest will be conducted on Bitcoin. Additionally, a stress test will be performed by modifying the periods of the Donchian channels' lines and the initial distance of the Stop Loss. For each test, the following metrics will be defined:

The results can be seen in the table below.

      N. Trades Avg. Loss Avg. Gain Winrate Frequency Spectancy Max. DD Kelly
SL Margin Indicator Order                
1 50 50 20 20 MARKET 44 -2.39% 51.23% 29.55% 1.82% 13.45% 13.29% 26.26%
LIMIT 40 -3.72% 36.80% 32.50% 1.66% 9.45% 23.10% 25.67%
STOP 47 -2.96% 41.52% 27.66% 2.08% 9.34% 17.27% 22.51%
20 20 10 10 MARKET 44 -2.39% 51.23% 29.55% 1.82% 13.45% 13.29% 26.26%
LIMIT 40 -3.72% 36.80% 32.50% 1.66% 9.45% 23.10% 25.67%
STOP 47 -2.96% 41.52% 27.66% 2.08% 9.34% 17.27% 22.51%
20 10 10 5 MARKET 44 -2.39% 51.23% 29.55% 1.82% 13.45% 13.29% 26.26%
LIMIT 40 -3.72% 36.80% 32.50% 1.66% 9.45% 23.10% 25.67%
STOP 47 -2.96% 41.52% 27.66% 2.08% 9.34% 17.27% 22.51%
2 50 50 20 20 MARKET 46 -2.40% 47.68% 28.26% 1.91% 11.76% 15.60% 24.65%
LIMIT 40 -3.78% 37.72% 32.50% 1.66% 9.71% 25.87% 25.74%
STOP 51 -2.83% 41.36% 25.49% 2.26% 8.43% 25.02% 20.39%
20 20 10 10 MARKET 46 -2.40% 47.68% 28.26% 1.91% 11.76% 15.60% 24.65%
LIMIT 40 -3.78% 37.72% 32.50% 1.66% 9.71% 25.87% 25.74%
STOP 51 -2.83% 41.36% 25.49% 2.26% 8.43% 25.02% 20.39%
20 10 10 5 MARKET 46 -2.40% 47.68% 28.26% 1.91% 11.76% 15.60% 24.65%
LIMIT 40 -3.78% 37.72% 32.50% 1.66% 9.71% 25.87% 25.74%
STOP 51 -2.83% 41.36% 25.49% 2.26% 8.43% 25.02% 20.39%
4 50 50 20 20 MARKET 46 -2.43% 43.32% 30.43% 1.91% 11.49% 16.37% 26.53%
LIMIT 40 -3.85% 37.98% 32.50% 1.66% 9.74% 28.14% 25.65%
STOP 54 -3.04% 39.60% 24.07% 2.39% 7.22% 31.18% 18.24%
20 20 10 10 MARKET 46 -2.43% 43.32% 30.43% 1.91% 11.49% 16.37% 26.53%
LIMIT 40 -3.85% 37.98% 32.50% 1.66% 9.74% 28.14% 25.65%
STOP 54 -3.04% 39.60% 24.07% 2.39% 7.22% 31.18% 18.24%
20 10 10 5 MARKET 46 -2.43% 43.32% 30.43% 1.91% 11.49% 16.37% 26.53%
LIMIT 40 -3.85% 37.98% 32.50% 1.66% 9.74% 28.14% 25.65%
STOP 54 -3.04% 39.60% 24.07% 2.39% 7.22% 31.18% 18.24%
6 50 50 20 20 MARKET 46 -2.42% 43.09% 30.43% 1.91% 11.43% 16.64% 26.53%
LIMIT 40 -3.89% 38.11% 32.50% 1.66% 9.76% 29.43% 25.61%
STOP 54 -3.13% 42.88% 22.22% 2.39% 7.09% 28.26% 16.54%
20 20 10 10 MARKET 46 -2.42% 43.09% 30.43% 1.91% 11.43% 16.64% 26.53%
LIMIT 40 -3.89% 38.11% 32.50% 1.66% 9.76% 29.43% 25.61%
STOP 54 -3.13% 42.88% 22.22% 2.39% 7.09% 28.26% 16.54%
20 10 10 5 MARKET 46 -2.42% 43.09% 30.43% 1.91% 11.43% 16.64% 26.53%
LIMIT 40 -3.89% 38.11% 32.50% 1.66% 9.76% 29.43% 25.61%
STOP 54 -3.13% 42.88% 22.22% 2.39% 7.09% 28.26% 16.54%

As you can see, the type of order used to open the position influences quite a bit, probably because daily levels are used for placing limit or stop orders. Furthermore, an increase in the maximum drawdown and a decrease in the mathematical expectation can be observed as the Stop Loss margin is widened. This is because the position size will be smaller, and the gains will not be able to compensate for the losses incurred in the drawdowns as easily. It is also reflected in the decrease in average gains and the increase in average losses. While there is more room for potential price movement due to noise, reliability is somewhat higher, although overall it is very low, as is typical in this type of strategy. The following graph shows a balance curve obtained during the backtest, applying commissions that would translate to 15% of the gross return of the trades on average. This balance is calculated on a daily basis, so the maximum drawdown amounts to 54%. This is because the price can rise much faster than the dynamic Stop Loss and make a significant retracement before ultimately recovering much of that retracement and closing the trade. The drawdown calculated in this way would take into account unrealized gains, whereas those seen in the previous table are based on realized gains. The graph shows the few periods with large returns and the false signals in between.

Conclusion

Trend-following strategies are difficult to operate discretionally but can be very profitable if done wisely. This example is not representative since Bitcoin is an asset with a rather atypical return, and furthermore, a universe of a single asset has been considered when these types of strategies benefit greatly from larger and uncorrelated universes. If you want to learn more about this type of strategy, read the blogs of Nick Radge (The Chartist - Share Trading Strategies & Technical Analysis) and Robert Carver (This Blog is Systematic). Both are specialized managers in trend-following who are still active and create educational content; the former leans more towards discretionary strategies, and the latter towards continuous strategies.



Categories:
trading python indicators