Trend Following Anatomy - where the profit comes from

Trend Following Anatomy shows on your own chart how trend following makes its money: most trades lose a little, a few long moves deliver the whole profit, and the drawdown is smaller than when you simply hold. The script runs one plain trend rule and takes its result apart trade by trade.
What the chart above shows
SPY, daily, adjusted for dividends, the last 2520 bars (12 Oct 2016 to 21 Oct 2026), rule "close above the 200-bar SMA", long only, 0.10% cost per side:
This is the typical result on a single rising index: the rule earns less than holding, falls less, and almost all of its profit sits in a handful of long trends. The trade ladder at the right end of the pane and the boxes on the price chart make this visible.
The foundation this makes visible, and the evidence for it
Trend following does not depend on being right often. It depends on positive skew: losses are cut early and stay small, gains are allowed to run. A rule that is wrong most of the time can therefore still make money, and most of its result comes from a few large moves, often while other markets fall hard. That shape is what this script measures, on any instrument and timeframe.
The evidence that this works comes from portfolios across many markets, not from a single chart:
What the evidence does not show is that trend following beats simply being long. In our test the Sharpe ratio was not distinguishable from a control that stays long whatever rose in the past (0.47 vs 0.45), which matches the critique by Huang, Li, Wang and Zhou (Journal of Financial Economics, 2020). The difference was the drawdown (-20% vs -33%) and the skew (+0.47 vs -0.54), and in calm years the trend portfolio mostly trailed a simple long position. The part that holds up is the shape: small losses, a few large gains, and protection when markets fall hard. This script lets you check that shape on your own instruments.
How it works
What you see
How to use it
Values for other scripts: position (1, 0, -1), the result of a trade closed on the bar, the rule value and buy & hold are in the Data Window and can be selected as a source. Alerts: "Rule turns long" and "Rule leaves long", both on the closed signal bar.
Limitations
License
Open source under the Mozilla Public License 2.0. All code in this script is the author's own.
Deutsch (Kurzfassung)
Trend Following Anatomy zeigt auf dem eigenen Chart, wie Trendfolge ihr Geld verdient: Die meisten Trades verlieren wenig, wenige lange Bewegungen bringen den Gewinn, und der Rückgang ist kleiner als beim Halten. Im Chart oben (SPY, Tageskerzen, dividendenbereinigt, 2016 bis 2026, Schluss über SMA 200): 25 Trades, 40 % Gewinner, die besten 5 Trades brachten 122 % des Nettogewinns. Regel +186,5 % gegen Halten +323,6 %, größter Rückgang -20,4 % gegen -33,7 %.
Die Grundlage: Trendfolge lebt von positiver Schiefe, nicht von einer hohen Trefferquote. Belegt ist das für Depots über viele Märkte. Hurst, Ooi und Pedersen (2017) fanden auf 67 Märkten von 1880 bis 2016 in jedem Jahrzehnt positive Durchschnittserträge. In unserem Test auf 56 Terminmärkten (2011 bis 2026, nach Kosten) lag die Sharpe-Ratio bei 0,47 und der größte Rückgang bei -20,4 %. In den zehn schwächsten S&P-500-Monaten gewann das Depot im Mittel 5,3 %, der S&P 500 verlor im Mittel 8,5 %.
Nicht belegt ist ein Mehrertrag gegenüber einfachem Long-Sein (Sharpe 0,47 gegen 0,45 bei einer Kontrolle). Der Vorteil liegt im kleineren Rückgang und in der Schiefe. Nur Vergangenheit, keine Prognose, keine Empfehlung. Rechenregeln und Bedienung stehen im englischen Teil.
What the chart above shows
SPY, daily, adjusted for dividends, the last 2520 bars (12 Oct 2016 to 21 Oct 2026), rule "close above the 200-bar SMA", long only, 0.10% cost per side:
- 25 trades, only 40% of them winners. The median trade lost 0.5%.
- The best 5 trades (20%) made 122% of the net profit. Without the 3 best trades, the sum of all trades is -4.1%.
- The rule gained +186.5%, buy & hold +323.6%. The largest drawdown was -20.4% for the rule and -33.7% for buy & hold.
This is the typical result on a single rising index: the rule earns less than holding, falls less, and almost all of its profit sits in a handful of long trends. The trade ladder at the right end of the pane and the boxes on the price chart make this visible.
The foundation this makes visible, and the evidence for it
Trend following does not depend on being right often. It depends on positive skew: losses are cut early and stay small, gains are allowed to run. A rule that is wrong most of the time can therefore still make money, and most of its result comes from a few large moves, often while other markets fall hard. That shape is what this script measures, on any instrument and timeframe.
The evidence that this works comes from portfolios across many markets, not from a single chart:
- Hurst, Ooi and Pedersen (Journal of Portfolio Management, 2017) tested 1-, 3- and 12-month trend rules on 67 markets in four asset classes from 1880 to 2016. They found positive average returns in every decade, and the strategy did well in 8 of the 10 largest drawdowns of a 60/40 stock and bond portfolio.
- Our own test of a diversified trend-following portfolio on 56 futures markets (CME and Eurex, November 2011 to October 2026, 15% volatility target, after costs): Sharpe ratio 0.47, largest drawdown -20.4%. In the ten weakest S&P 500 months of the period the S&P 500 lost 8.5% on average, while the portfolio gained 5.3% on average. Market-years with large moves (29% of all market-years) delivered 159% of the gross profit; the rest cost money.
What the evidence does not show is that trend following beats simply being long. In our test the Sharpe ratio was not distinguishable from a control that stays long whatever rose in the past (0.47 vs 0.45), which matches the critique by Huang, Li, Wang and Zhou (Journal of Financial Economics, 2020). The difference was the drawdown (-20% vs -33%) and the skew (+0.47 vs -0.54), and in calm years the trend portfolio mostly trailed a simple long position. The part that holds up is the shape: small losses, a few large gains, and protection when markets fall hard. This script lets you check that shape on your own instruments.
How it works
- One rule per run. Moving average (default): long while the close is above the SMA (200), out when it closes below. Two EMAs: long while EMA 50 is above EMA 200. Breakout (Donchian): long after a close above the highest high of 50 bars, out after a close below the lowest low of 25 bars. "Long only" (default) means long or flat; "Long and short" is always in the market.
- Signals use closed bars only, and every change of position is filled at the open of the next bar, so nothing repaints and no bar looks ahead. Costs are charged on entry and exit (0.10% per side by default).
- Trade result = exit / entry - 1 - 2 x cost (mirrored for shorts). Rule value = product of (1 + trade result), with an open trade valued at the current close. Buy & hold = close / close at the start. Drawdown = distance from the running high.
- Best 20% = the trades with the highest results; their sum divided by the net profit of all trades. It can exceed 100% when the remaining trades lost money in total.
- By default the last 2520 bars are analysed (about ten years of daily bars). Set "Analyse the last N bars" to 0 for the whole history, or choose a start date.
What you see
- Price chart: boxes for the best 20% of trades with their result; optionally all other trades as faint boxes.
- Pane: the rule value after costs and buy & hold, both in percent; periods in which the rule is more than 10% below its own high are shaded.
- Trade ladder: every closed trade, sorted from worst to best, at the right end of the pane.
- Table: trades, time in market, win rate, average win and loss, payoff, profit factor, share of the best 20%, result without the 3 best trades, median and mean trade, rule vs buy & hold, largest drawdown of both.
How to use it
- Add it to any chart and read the table first: win rate, payoff and the share of the best trades tell you what kind of rule this is on this market.
- Look at the ladder and the boxes: these are the moves the rule lived from.
- Compare the drawdowns, not only the totals.
- Change the rule or the lengths. If a small change flips the result, the result was not robust.
Values for other scripts: position (1, 0, -1), the result of a trade closed on the bar, the rule value and buy & hold are in the Data Window and can be selected as a source. Alerts: "Rule turns long" and "Rule leaves long", both on the closed signal bar.
Limitations
- History only. No forecast and no recommendation. The numbers change with the range, the timeframe and the instrument.
- Dividends count only if the chart is adjusted for them (the "ADJ" button). The example above uses adjusted data; without adjustment the same SPY range shows 29 trades and +261.7% for buy & hold.
- Costs are an assumption. There are no taxes, no interest on cash, and no special treatment of overnight gaps on intraday charts.
- One market and one rule per run. The portfolio evidence above cannot be reproduced on a single chart: the script shows the shape of trend following, not its portfolio result.
License
Open source under the Mozilla Public License 2.0. All code in this script is the author's own.
Deutsch (Kurzfassung)
Trend Following Anatomy zeigt auf dem eigenen Chart, wie Trendfolge ihr Geld verdient: Die meisten Trades verlieren wenig, wenige lange Bewegungen bringen den Gewinn, und der Rückgang ist kleiner als beim Halten. Im Chart oben (SPY, Tageskerzen, dividendenbereinigt, 2016 bis 2026, Schluss über SMA 200): 25 Trades, 40 % Gewinner, die besten 5 Trades brachten 122 % des Nettogewinns. Regel +186,5 % gegen Halten +323,6 %, größter Rückgang -20,4 % gegen -33,7 %.
Die Grundlage: Trendfolge lebt von positiver Schiefe, nicht von einer hohen Trefferquote. Belegt ist das für Depots über viele Märkte. Hurst, Ooi und Pedersen (2017) fanden auf 67 Märkten von 1880 bis 2016 in jedem Jahrzehnt positive Durchschnittserträge. In unserem Test auf 56 Terminmärkten (2011 bis 2026, nach Kosten) lag die Sharpe-Ratio bei 0,47 und der größte Rückgang bei -20,4 %. In den zehn schwächsten S&P-500-Monaten gewann das Depot im Mittel 5,3 %, der S&P 500 verlor im Mittel 8,5 %.
Nicht belegt ist ein Mehrertrag gegenüber einfachem Long-Sein (Sharpe 0,47 gegen 0,45 bei einer Kontrolle). Der Vorteil liegt im kleineren Rückgang und in der Schiefe. Nur Vergangenheit, keine Prognose, keine Empfehlung. Rechenregeln und Bedienung stehen im englischen Teil.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.