What is the Half-Trend Strategy?

Half-Trend is a sophisticated trend-following indicator that determines market direction using a combination of recent highest-highs, lowest-lows, and ATR-based channel bands. Unlike simple moving average crossovers, it uses a stateful loop algorithm that tracks the current trend counter โ€” only reversing when a genuine price breach of the channel occurs.

The result is a smooth trend signal that stays in trends longer and generates fewer whipsaws compared to most other trend indicators. It's particularly effective on 15-minute and hourly charts for NSE F&O instruments.

๐Ÿ’ก
Half-Trend uses a bar-by-bar iterative loop (for loop over BarCount) โ€” this is computationally heavier than vectorized AFL. For large histories, allow extra processing time. SetBarsRequired is not needed as the loop handles initialization.

Technical Specifications

Amplitude Param
3 (default)
Channel Deviation
3 (default)
ATR Period
100
ATR Divisor
2 (half ATR)
Upper Band
MA(High, Amp)
Lower Band
MA(Low, Amp)
ATR Channels
Show/Hide param
Position Size
1 lot (RoundLot)

How the Algorithm Works

The AFL uses a stateful iterative approach. On each bar, it checks:

  • If current trend is UP (trend > 0): Trail the main line to max of previous main and current low. If upper band falls below main AND close breaks below prior low โ†’ flip to DOWNTREND.
  • If current trend is DOWN (trend < 0): Trail the main line to min of previous main and current high. If lower band rises above main AND close breaks above prior high โ†’ flip to UPTREND.
  • If no prior trend (trend = 0): Initialize based on whether close is rising or falling relative to prior close.
Half-Trend.afl โ€” Core Loop Logic
// ATR Channel setup atr2 = ATR(100) / 2; dev = channelDeviation * atr2; upperBand = MA(High, amplitude); lowerBand = MA(Low, amplitude); for(i = 1; i < BarCount; i++) { if(trend[i-1] > 0) { // In uptrend main[i] = Max(main[i-1], currentLow[i]); if(upperBand[i] < main[i] AND Close[i] < Low[i-1]) { trend[i] = -1; // Flip to downtrend main[i] = Min(main[i-1], currentHigh[i]); } } // ... downtrend and init cases below }

Parameters & Tuning Guide

ParameterDefaultRangeEffect
Amplitude31โ€“10HHV/LLV lookback. Lower = faster reaction; higher = smoother but more lag.
Channel Deviation31โ€“10Width of ATR channel. Higher = wider bands, fewer signals. Lower = tighter, more signals.
Show ATR ChannelsSHOWSHOW/HIDEToggle the visual ATR channel bands on the chart.

Best Use Cases

๐Ÿ“ˆ

Positional Trading

On daily charts, Half-Trend identifies multi-week trends in Nifty 50 stocks. Amplitude=3, ChannelDev=3 works well for most large-cap NSE stocks.

โฑ๏ธ

Intraday Swing

On 15-minute charts with Amplitude=2, ChannelDev=2 for more reactive signals in BankNifty and MCX Gold futures.