HalfTrend Indicator: TradingView Pine Script for Trend and Buy/Sell Signals
Knowing when the trend has actually flipped—instead of chasing noise—is one of the hardest parts of trend trading. I've found the HalfTrend (HT) indicator useful for that. It draws a single trend line that switches between support and resistance, plus an ATR-based channel around it, and it marks Buy and Sell only when the internal trend state changes. That keeps signals clear and avoids the clutter of many overlapping lines.
HalfTrend uses the Average True Range (ATR) and a short lookback (amplitude) to decide when price has broken the current structure. When the trend flips from down to up, you get a Buy signal and the line turns into support (often shown in blue); when it flips from up to down, you get a Sell signal and the line acts as resistance (often shown in red). The ATR High and ATR Low bands form a ribbon that shows the channel around the trend line. After testing it on multiple timeframes, I use it mainly as a trend filter and for reversal entries when the arrow and label appear. In this guide you'll see how HalfTrend is built, how to add and tune it in TradingView (including via Pineify), and how to use it in real strategies with clear entry, stop-loss, and take-profit rules.
What is HalfTrend?
HalfTrend (HT) is an overlay trend-following indicator that plots one main line (the HalfTrend line) plus an ATR-based channel (ATR High and ATR Low). The line switches between acting as support in uptrends and resistance in downtrends. Buy and Sell signals appear only when the internal trend state flips—not on every bar—which reduces noise compared to raw moving-average crossovers.
The logic is built from:
- Amplitude: Lookback period used to find the highest high and lowest low, and to compute SMAs of high and low. Default is 2; larger values smooth the trend but add lag.
- Channel deviation: Multiplier applied to half of the 100-period ATR to set the distance of the ATR High and ATR Low bands from the HalfTrend line. Default is 2; higher values widen the channel.
- ATR: The indicator uses
ta.atr(100) / 2(half of 100-period ATR) for both the arrow offset and, with channel deviation, the channel width. - Trend state: Internally the indicator tracks trend (0 = up, 1 = down) and next_trend. It flips to downtrend when the high SMA crosses below the tracked max low and close is below the prior low; it flips to uptrend when the low SMA crosses above the tracked min high and close is above the prior high.
- HalfTrend line (HT): In an uptrend it equals the “up” level (support); in a downtrend it equals the “down” level (resistance).
- Buy signal: Fires when trend switches from 1 to 0 (downtrend to uptrend).
- Sell signal: Fires when trend switches from 0 to 1 (uptrend to downtrend).
The ATR High and ATR Low bands form a ribbon around the HT line, so you can see the channel at a glance. What makes HalfTrend useful is the single line that changes role (support/resistance) and the explicit Buy/Sell only on trend change, which fits well with other trend tools such as Supertrend or SSL Channel for confirmation.
How to Add HalfTrend to TradingView
TradingView does not list a built-in indicator named "HalfTrend." You can add it in two ways:
Option 1 – Pineify (recommended)
- Open Pineify and open the Pine Script editor.
- Search for "HalfTrend" or "HT" in the indicator library.
- Add the indicator to your layout and adjust inputs (Amplitude, Channel Deviation) and style (Up/Down trend line, ATR High/Low, ribbons, arrows, Buy/Sell labels).
- Copy the generated Pine Script into TradingView's Pine Editor and add it to your chart.
Option 2 – TradingView Pine Editor
- In TradingView, open the Pine Editor and paste a HalfTrend script (e.g. from the community or the one in this article).
- Click "Add to chart." The indicator will overlay on the price chart.
- Open the indicator settings (gear icon) to change Amplitude, Channel Deviation, and visual options.
Typical inputs are: Amplitude (default 2; higher = smoother, more lag), Channel Deviation (default 2; higher = wider channel). The process with Pineify usually takes about five minutes including customization.
How to Use HalfTrend (Practical Trading Strategies)
HalfTrend works best as a trend filter and for reversal-style entries when the arrow and Buy/Sell label appear. Below are concrete ways to use it.
Strategy #1: Trend flip (Buy/Sell on signal only)
- Setup: HalfTrend on the chart; default Amplitude 2 and Channel Deviation 2, or your chosen values.
- Entry: Long on Buy signal (trend flips from down to up); short on Sell signal (trend flips from up to down). Optionally require a close beyond the HT line to avoid noise.
- Stop-loss: Below the recent swing low (longs) or above the recent swing high (shorts), or just beyond the opposite ATR band.
- Take-profit: Next opposite signal, or a fixed risk multiple (e.g. 1.5–2R).
Strategy #2: Trend filter for other entries
- Setup: Use HalfTrend to define bias: blue HT line and ribbon = only look for longs; red = only look for shorts.
- Entry: Use your usual entry (e.g. pullback to the HT line, breakout, or another indicator) but only when HalfTrend bias agrees.
- Stop-loss: Based on your entry method (e.g. below pullback low for longs).
- Take-profit: Your normal target or trailing stop.
Strategy #3: HT line as dynamic support/resistance
- Setup: In an uptrend, the HT line acts as support; in a downtrend, as resistance. Use the ATR bands as a buffer.
- Entry: Long on a pullback to the HT line (or ATR Low) in an uptrend with no Sell signal yet; short on a rally to the HT line (or ATR High) in a downtrend with no Buy signal yet.
- Stop-loss: Below ATR Low (longs) or above ATR High (shorts).
- Take-profit: Next opposite HalfTrend signal or a logical level.
Strategy #4: Multi-timeframe HalfTrend
- Setup: Check HalfTrend on a higher timeframe (e.g. daily) for trend; use a lower timeframe (e.g. 4H or 1H) for timing.
- Entry: When higher-timeframe HalfTrend is bullish, take only Buy signals (or pullback longs) on the lower timeframe; when bearish, take only Sell signals (or pullback shorts).
- Stop-loss: On the timeframe you enter (e.g. below/above the signal bar or recent swing).
- Take-profit: Logical level or trailing stop.
I've found HalfTrend particularly useful on 4H and daily for swing trades; on shorter timeframes I sometimes increase Amplitude slightly to reduce whipsaws and combine it with RSI or volume for confirmation.
Best HalfTrend Settings
Settings should match your timeframe and style. Below are practical starting points.
Scalping (1–5 minute charts)
- Amplitude: 2–3.
- Channel Deviation: 2.
- Defaults can work; slightly higher Amplitude may cut some noise.
Day trading (15–60 minute charts)
- Amplitude: 2–4.
- Channel Deviation: 2–3.
- Balances responsiveness and false flips.
Swing trading (4H–daily charts)
- Amplitude: 2–5.
- Channel Deviation: 2–3.
- Slightly higher Amplitude on daily can smooth the trend line.
Position trading (daily/weekly)
- Amplitude: 3–6.
- Channel Deviation: 2–3.
- Focus on major trend; fewer signals, higher commitment.
In general: higher Amplitude = smoother HT line and fewer signals but more lag; higher Channel Deviation = wider ATR bands and more room for pullbacks. No indicator works 100% of the time; always use stop-loss and position sizing.
Advanced HalfTrend Techniques
Multi-timeframe analysis
Use HalfTrend on a higher timeframe for trend direction, then use the same or a slightly different HalfTrend on a lower timeframe for exact entry on the next Buy/Sell signal or pullback in the direction of the higher-timeframe trend.
Combining with other indicators
- RSI: Use RSI overbought/oversold at HalfTrend flips to filter or confirm (e.g. only take Buy when RSI was oversold).
- Volume: Require above-average volume on the signal bar for conviction.
- MACD or other trend indicators: Use HalfTrend for bias and MACD/trend for timing (e.g. MACD cross in the direction of HalfTrend).
Risk and pitfalls
- HalfTrend can whipsaw in tight ranges; consider a higher Amplitude or a filter (e.g. only trade when price is not chopping around the HT line for many bars).
- No indicator works every time; always use stop-loss and position sizing.
- On very short timeframes, you can disable or reduce Buy/Sell labels if the chart gets cluttered.
How to Backtest HalfTrend
Backtesting helps you see if your HalfTrend-based rules add value before risking capital. In the Pineify Editor you can build a strategy that uses HalfTrend in the conditions and then backtest it.
Typical strategy elements:
- Entry/exit conditions: e.g. Buy signal = long, Sell signal = short; or use HalfTrend bias (up/down) plus your own entry rule.
- Market orders: long/short when conditions are met.
- Take profit: fixed target, opposite signal, or level-based.
- Stop loss: below/above recent swing or the opposite ATR band.
- Trailing stop (optional): to lock in profits when trend extends.
Risk management:
- Risk 1–2% of capital per trade (position size so that stop distance equals 1–2% of account).
- Limit how many concurrent positions you have.
- Test on multiple symbols and timeframes to see where the edge holds.
No indicator works every time; backtesting shows whether your HalfTrend setup has a positive expectancy and in which markets/timeframes it works best.
FAQs
What is the best Amplitude for HalfTrend?
Default 2 is common and works well for many timeframes. Use 2–3 for scalping/day trading and 3–6 for swing/position trading. Higher Amplitude = smoother line and fewer signals but more lag.
What is Channel Deviation in HalfTrend?
Channel Deviation is a multiplier applied to half of the 100-period ATR. It sets how far the ATR High and ATR Low bands are from the HalfTrend line. Default 2 is typical; higher values widen the channel and give more room for pullbacks.
Can I use HalfTrend for crypto?
Yes. Crypto can be volatile, so HalfTrend may flip more often on default settings. Slightly higher Amplitude (e.g. 3–4) on higher timeframes can reduce noise; always use stops and size appropriately.
Why does HalfTrend use ATR(100)?
The indicator uses a 100-period ATR (and half of it) for the channel and arrow offset so the bands adapt to recent volatility. It is fixed in the classic formulation; you cannot change the ATR length in the standard inputs (only Amplitude and Channel Deviation).
How do I avoid whipsaws with HalfTrend?
Use a higher Amplitude, trade only in the direction of a higher-timeframe HalfTrend, or require a second confirmation (e.g. close beyond the HT line, or RSI/volume). Avoiding very low Amplitude in choppy markets also helps.
Can I combine HalfTrend with RSI or MACD?
Yes. Use HalfTrend for trend bias and Buy/Sell flips; use RSI or MACD for overbought/oversold or momentum confirmation. For example: only take HalfTrend Buy when RSI is not overbought, or only take HalfTrend Sell when MACD is bearish. Keep the rule set simple so backtests stay interpretable.
HalfTrend works best when you use it as a trend filter and combine it with clear risk rules. Key takeaways:
- HalfTrend plots one trend line (HT) plus ATR High/Low bands; Buy when trend flips from down to up, Sell when it flips from up to down.
- Add it via Pineify or TradingView Pine Editor and tune Amplitude and Channel Deviation for your timeframe.
- Use practical strategies: trend flip only, trend filter for other entries, HT line as dynamic S/R, or multi-timeframe HalfTrend.
- Match settings to style (default or slightly higher Amplitude for swing/position).
- Backtest with clear entry, stop-loss, and take-profit rules and 1–2% risk per trade.
- Test on a demo or small size before going live.



