Explainers / HalfTrend
HalfTrend, explained from the source
HalfTrend by everget is one of the most-boosted trend lines on TradingView: a blue or red stepped line, a shaded ATR ribbon, and Buy and Sell labels where it changes colour. It looks like a Supertrend or a Chandelier Exit, and most people assume the ATR drives it. The published source shows otherwise. The line and every Buy and Sell label come from recent highs, lows and closes only. The ATR draws the ribbon and places the arrows, and nothing else. So of the two settings, only one changes the signals.
The two settings
- Amplitude (default 2): how many bars the script looks back. It uses the highest high and the lowest low of the last Amplitude bars, and simple averages of the highs and of the lows over the same bars.
- Channel Deviation (default 2): the ribbon is drawn at the line plus and minus Channel Deviation times half of a 100-bar ATR. The 100 is fixed in the code, not an input.
The line: a ratchet built from highs and lows
While the line is blue (up), the script keeps track of the highest "recent low" since the last flip, where a recent low is the lowest low of the last Amplitude bars. The line takes that value and never moves down while it stays blue.
While the line is red (down), it mirrors this: it tracks the lowest "recent high" since the last flip and never moves up.
When the colour changes, the new line starts from where the old one was on the previous bar, so the line has no gap at a flip.
The flip rule
A blue line turns red on the first bar where both of these hold:
- the average of the last Amplitude highs is below that highest recent low, and
- the close is below the previous bar's low.
A red line turns blue on the mirror: the average of the last Amplitude lows is above the lowest recent high, and the close is above the previous bar's high.
There is no ATR anywhere in that rule. The Buy label prints on the bar the line turns blue, and Sell on the bar it turns red. The arrows and labels are drawn at the edge of the ATR ribbon, which is why they sit at a tidy distance from price; that distance is decoration.
What the settings change
Channel Deviation changes no signals. Raising it from 2 to 5 makes the ribbon wider and nothing else: every flip, every label and every alert stays on the same bar. Many "best settings" guides tune it as if it filtered signals.
Amplitude is the only setting that matters. A longer look-back needs a bigger turn before the averages cross back, so it flips later and less often. On random-walk prices (our simulation, 200,000 bars):
| Amplitude | flip every | flipped back within 5 bars | move from extreme close to flip |
|---|---|---|---|
| 2 (default) | 16 bars | 16% | 2.6 bar ranges, 5 bars later |
| 3 | 21 bars | 6% | 3.1 bar ranges, 7 bars later |
| 5 | 30 bars | under 1% | 3.9 bar ranges, 10 bars later |
| 10 | 49 bars | none | 5.1 bar ranges, 16 bars later |
Fewer labels that reverse quickly, and later labels, are the same setting seen from two sides. Random-walk prices have nothing to predict, so these numbers describe how the rule reacts to noise, not how it trades.
Does HalfTrend repaint?
On closed bars, no: the line and the labels use only the current and past bars, and nothing is plotted with an offset. On the bar still forming, the high, low and close are live, so a label can appear mid-bar and vanish before the close. Set alerts to "once per bar close" if you only want closed-bar labels. More in what repainting is, or test a script with the repaint checker.
HalfTrend vs Supertrend and Chandelier Exit
Supertrend and Chandelier Exit place their line a multiple of ATR away from price, so volatility sets how far price must turn. HalfTrend's line sits on actual recent lows or highs, and its flip needs the bar averages to cross that line plus a close beyond the previous bar. There is no volatility multiple to widen or narrow, so the size of turn it needs is set by the bars themselves and by Amplitude.
Where it fails
- The label is a trailing stop, not a forecast. It prints only after price has already turned from its extreme, a median of 5 bars later at the default.
- It labels noise, often. At Amplitude 2 it flipped about every 16 bars on random-walk prices, and about one flip in six reversed within 5 bars.
- The ribbon looks like a filter but is not one. Channel Deviation and the 100-bar ATR only draw the band and place the arrows.
- One setting, one trade-off. Raising Amplitude removes quick reversals by waiting for a bigger turn. There is no setting that gives earlier labels with fewer reversals, and the script contains no test of any setting.
- Open-bar labels. A label on the bar still forming can disappear before the close.
- "Buy" and "Sell" are names, not results. On a finished chart every label sits near a turn; live, each one came after the move it is named for.
Also explained: Chandelier Exit · Supertrend · UT Bot Alerts · Repainting
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. HalfTrend is by everget on TradingView; this page explains its published open-source code and is not affiliated with the author.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.