If letting profits run is key to the success of a trend following approach, is there a way to take profit without diminishing returns?
Most trend following approaches win less than 40% of the time. So, the big profitable trades are what saves the day for this type of trading approach. However, it is pure pain to simply sit there and watch a large profit erode, just because the criteria to exit the trade takes many days to be met.
Three methods to take a profit on a Trend Following algorithm
- Simple profit objective – take a profit at a multiple of market risk.
- Trail a stop (% of ATR) after a profit level (% of ATR) is achieved.
- Trail a stop (Donchian Channel) after a profit level (% of ATR) is achieved.
Use an input switch to determine which exit to incorporate
The switch determines which exit to use later in the code. Using inputs to allow the user to change via the interface also allows us to use an optimizer to search for the best combination of inputs. I used MultiCharts Portfolio Trader to optimize across a basket of 21 diverse markets. Here are the values I used for each exit switch.
MR = Market risk was defined as 2 X avgTrueRange(15).
- Pure profit objective -Multiple from 2 to 10 in increments of 0.25. Take profit at entryPrice + or – Profit Multiple X MR
- Trailing stop using MR – Profit Thresh Multiple from 2 to 4 in increments of 0.1. Trailing Stop Multiple from 1 to 4 in increments of 0.1.
- Trailing stop using MR and Donchian Channel – Profit Thresh Multiple from 2 to 4 in increments of 0.1. Donchian length from 3 to 10 days.
Complete strategy code incorporating exit switch. This code is from Michael Covel’s 2005 Trend Following book (Covel, Michael. Trend Following: How Great Traders Make Millions in Up or Down Markets. FT Press, 2005.) This strategy is highlighted in my latest installment in my Easing into EasyLanguage series – Trend Following edition.
Here’s the fun code from the complete listing.
The first exit is rather simple – just get out on a limit order at a nice profit level. The second and third exit mechanisms are a little more complicated. The key variable in the code is the maxContractProfit keyword. This value stores the highest level, from a long side perspective, reached during the life of the trade. If max profit exceeds the exit2ThreshATRMult, then trail the apex by exit2TrailATRMult. Let’s take a look at the math from a long side trade.
if maxContractProfit > (exit2ThreshATRMult * marketRiskPoints ) * bigPointValue
Since maxContractProfit is in dollar you must convert the exit2ThreshATRMult X marketRiskPoints into dollars as well. If you review the full code listing you will see that I convert the dollar value, marketRisk, into points and store the value in marketRiskPoints. The conversion to dollars is accomplished by multiplying the product by bigPointValue.
sell("Lxit-2") next bar at entryPrice + maxContractProfit / bigPointValue - exit2TrailATRMult * marketRiskPoints stop;
I know this looks complicated, so let’s break it down. Once I exceed a certain profit level, I calculate a trailing stop at the entryPrice plus the apex in price during the trade (maxContractProfit / bigPointValue) minus the exit2TrailATRMult X marketRiskPoints. If the price of the market keeps rising, so will the trailing stop. That last statement is not necessarily true, since the trailing stop is based on market volatility in terms of the ATR. If the market rises a slight amount, and the ATR increases more dramatically, then the trailing stop could actually move down. This might be what you want. Give the market more room in a noisier market. What could you do to ratchet this stop? Mind your dollars and your points in your calculations.
The third exit uses the same profit trigger, but simply installs an exit based on a shorter term Donchian channel. This is a trailing stop too, but it utilizes a chart point to help define the exit price.
Results of the three exits
Exit 1 – Pure Profit Objective
Take a profit on a limit order once profit reaches a multiple of market risk aka 2 X ATR(15).
The profit objective that proved to be the best was using a multiple of 7. A multiple of 10 basically negates the profit objective. With this system several profit objective multiples seemed to work.
Exit – 2 – Profit Threshold and Trailing Stop in terms of ATR or market risk
Trail a stop a multiple of ATR after a multiple of ATR in profit is reached.
3-D view of parameters
This strategy liked 3 multiples of ATR of profit before trailing and applying a multiple of 1.3 ATR as a stop.
Like I said in the video, watch out for 1.3 as you trailing amount multiple as it seems to be on a mountain ridge.
Exit – 3 – Profit Threshold in terms of ATR or market risk and a Donchain Channel trailing stop
Trail a stop using a Donchian Channel after a multiple of ATR in profit is reached. Here was a profit level is reached, incorporate a tailing stop at the lowest low or the highest high of N days back.
3-D view of parameters
Conclusion
The core strategy is just an 89-day Donchian Channel for entry and a 13-Day Donchian Channel for exit. The existing exit is a trailing exit and after I wrote this lengthy post, I started to think that a different strategy might be more appropriate. However, as you can see from the contour charts, using a trailing stop that is closer than a 13-day Donchian might be more productive. From this analysis you would be led to believe the ATR based profit and exit triggers (Exit #2) is superior. But this may not be the case for all strategies. I will leave this up to you to decide. Here is the benchmark performance analysis with just the core logic.
If you like this type of explanation and code, make sure you check at my latest book at amazon.com. Easing into EasyLanguage – Trend Following Edition.