Price Action Lab Blog

Premium Market Analysis

Trading Strategies

Trailing Stops and Curve-Fitting in Trading System Development

Traders use a trailing stop to let profits run and cut losses. This type of order sets a suitable stop-loss order at a percentage below (above) market price after a long (short) position is established. The intention is to limit losses while preserving profits. This type of stop order can be very useful during real trading but its use during trading system development and especially by programs that automatically design trading systems is highly questionable because of the potential of curve-fitting a price series.

The objective of trading system developers should be to identify robust setups and not to just design systems with a nice looking equity curve in the in-sample and in the out-of-sample. These two tasks are not equivalent but unfortunately inexperienced trading systems developers do not immediately realize the difference but only after they get too frustrated with real time performance. For example, using a trailing stop during trading system development based on historical data is highly likely to produce curve-fitted results. Why? Because this is exactly what a trailing stop is supposed to do. As a result of the use of such stop, the entry signals lose their significance and even if they are random, the performance may look like that of a system with great potential although in reality it is just a curve-fit.

Some users of software that designs trading system are not aware that trailing stops often render entry signals irrelevant because they have the potential of curve-fitting profits to a price curve. This becomes a potential source of disaster when during the in-sample and out-of-sample the price series exhibits smooth trends but during actual trading there is a prolonged period of sideways price action. Thus, as we will see with specific examples, a system using trailing stops that tests profitable in the out-of-sample can generate losses during actual trading because of a shift in the dynamics of the prices series.

Example 1:

For this example I selected a random but not weird looking system for SPY that establishes a long position at the open of next bar when the close of a bar is greater than the high of the previous bar. With a backtesting period from 01/2000 to present on daily data, for fixed profit-target and stop-loss of 2% this system shows a win rate of 48.83% and a profit factor equal to 0.91. Thus, this is basically a losing system nobody would trade. ($14 round trip commission and slippage was included). 

However, after setting a trailing stop of 5% – Edit: defined as a percentage of market price, not as a drop from maximum open profit – one can see that the win rate drops to 37.60% but the profit factor rises to 1.09. Of course, there is a dramatic reduction in the number of trades from about 380 to about only 69. The equity curve of this backtest is shown below:

Notice how the equity curve looks similar to the price curve. When the trend goes up the equity curve goes up for this simple system. This is what the trailing stop is supposed to accomplish and this is what traders are looking for when following trends. The point is that this is not a good practice when developing automated trading systems. As already argued, the entry signal is now rendered irrelevant and the exit function, the trailing stop, determines the behavior of the system. Thus, the argument is that although this is type of a stop is useful in actual trading, it may be causing deceiving results during system development.

Example 2:

I used a random number generator and a system of the following form came up:

Buy when the low of 6 days ago is greater than the open of 18 days ago

You may or may not be amazed to know that there are programs sold to traders that generate entry conditions that look like the one above. Actually, those programs often select random entry conditions and turn them to a nice looking equity graph by the use of exit filters like the trailing stop. Inexperienced traders need time to understand what they are dealing with when using such programs. Experienced traders often know these facts but again these traders will rarely use such programs.

The above random entry condition in the same backtest period as before and with a 2% profit-target and stop-loss generated 341 trades with win rate of 51.32% and profit factor equal to 0.81, a losing system that is. The use of the small profit-target and stop-loss proves that this system has basically no predictive ability and it is, as it was expected due to its generation, random.

But this is what happens when a 1% trailing stop is used instead:

What a nice looking equity curve shown above! The trailing stop renders the random entry signal irrelevant and instead fits the performance to the price series. This is the mother of all curve-fits.

What is important to realize is that if someone tested this system in an in-sample to the end of 2009 for example, then the performance in the out-of-sample would appear as good or even better and the inexperienced trading system developer would think that this is a system worth considering. Actually, it is a junk system. It just happened that the out-of-sample included a trend and the trailing stop captured its profits. But that is not fully representative of what could happen in reality. For example, this is what could happen:

Instead of a trend in actual trading one could get a price series like the one shown in XLF above from 2000 to 2007. In this case, the system performance is a disaster, which proves that it was just a fitted system to some price data and the supposed out-of-sample performance did only validate that because of favorable price behavior. Therefore, this system generated signals with no predictive ability as already determined by the initial backtest with a fixed target and stop but the trailing stop gave the impression that this is something worth considering due to the presence of a suitable out-of-sample. When the price series in the future is not representative of the out-of-sample, disaster occurs.

Conclusion

Trailing stops are very useful in actual trading for letting profits run and cutting losses of a fundamentally non-random system. But when used during trading system development, the result may be a curve-fitted system because that is what trailing stops are supposed to do in the first place.  Software programs that include trailing stops as part of the available orders to be used when designing trading systems may generate misleading results when used by inexperienced traders. One reason that I do not use this type of stop when developing trading systems and in algorithms I have developed for machine design of trading systems is that it renders the entry signals irrelevant in most cases. However, the robustness of the entry signals and their predictive ability under the majority of possible market conditions is what secures longer-term positive performance for trading system. Trailing stops can be used during actual trading to enhance profits and cut losses. One way to check whether signals generated by a trading system have predictive ability is to set a small percent or dollar stop. If the profit  factor when the stops are set like that is not sufficiently high, you are probably dealing with a random entry generator.

The risk of curve-fitting is also high when using indicators to exit signals although entry signals may not be rendered irrelevant. But this is an even more interesting and complex case that will be the subject of another post. 

Disclosure: no relevant positions. 

Charting program: Amibroker (Charts created with AmiBroker – advanced charting and technical analysis software. http://www.amibroker.com/”) 

Disclaimer

Comments are Closed

Theme by Anders Norén