VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime

HalfTrend: a stair-step trend line that holds the last swing level

HalfTrend draws one stair-step line on the price chart. In an up leg it holds the highest swing low the move has defended and steps up only when the lows of recent bars rise above it; in a down leg it holds the lowest swing high and steps down. It turns only when the bars as a whole, not a single wick, have moved through that held level and the close confirms it, and a channel based on recent volatility is drawn around the line. This page explains how it is built, how it differs from Supertrend, how futures traders use it, and how a strategy generator can test it on your own contracts.

FamilyTrend
Also known asHalf Trend
OutputOne stair-step line with a channel around itPlotted on the price chart
In AlphaPrimeBuilt-in generator familyTurn, step, leg and channel conditions

What it measures

HalfTrend is a trend-following line drawn from price structure rather than from an average of closes. It states one thing at a time: the market is in an up leg or a down leg, and here is the level that leg has defended so far. Its origins are not well documented. It spread as a freely shared script in charting communities, and this page follows a widely used public version.

That public version works in plain steps. It looks back over a short window, called the amplitude, and notes the highest high, the lowest low, and the simple average of the highs and of the lows across that window. While the trend is up, it keeps a running record of the highest of those recent lowest lows; this held level is the line, so the line can rise or stay flat but never fall. The trend turns down only when two things happen on the same bar: the average of recent highs has dropped below the held level, and the close is below the previous bar's low. At that moment the line does not jump: it keeps its last value, which price has now fallen below, and the process runs in mirror image, holding the lowest of the recent highest highs and turning up only when the average of recent lows rises above it and the close clears the previous bar's high. Around the line, the indicator draws a channel whose distance from the line is a chosen multiple of half the average true range, measured over a long window.

Two consequences follow. First, the line's distance from price is set by structure, not by volatility: in a steady up leg it sits just under the latest defended low, and it moves only when the market has printed a higher one. Second, a turn demands more than a touch. A wick through the line, or even one close beyond it, is not enough while the average of the window still sits on the trend's side. The channel then puts the move in volatility terms. When price breaks the held level by more than the channel's width, the break is large compared with how restless the contract has been, and a rule can ask for that larger break before it acts.

Concept sketch (not real market data)

How it behaves in real markets

Compared with Supertrend, the difference is where volatility enters. Supertrend places its line a multiple of ATR away from the middle of the bar, so after a volatility spike its line widens and sits further from price. HalfTrend's line stays on the last defended swing extreme whatever volatility does, and volatility only sets the channel drawn around it. In a clean trend this gives a staircase of flat shelves joined by single steps, each shelf a higher low or a lower high that the market has respected. Pullbacks that hold above the shelf leave the reading untouched, and because the turn needs the window's average to cross as well, a brief spike through the line usually does not end the leg.

Choosing the settings is mainly about the amplitude. A shorter window lets the averages respond quickly, so the line steps more often and turns sooner, at the cost of more turns that reverse within a few bars. A longer window makes both the held level and the averages slower, so the line rides longer legs and gives back more before it turns. In the public version the channel settings change how wide the channel is, not when the line turns. Widening the channel to cut false turns therefore leaves the turns exactly where they were; it moves only a channel-based stop or filter. The useful comparison is how turn frequency and leg length hold up across different stretches of history, not which setting looked cleanest on one chart.

Two misreadings are common. The first is treating every turn as a reversal. In a choppy, sideways market the averages of highs and lows hover around the held level, the line turns and turns back, and the chart fills with alternating buy and sell arrows. Each turn says only that the defended level gave way by a little; it does not mark a top or a bottom, and taking each one as a fresh trade in a range produces a run of small whipsaws. A count of recent turns, or a separate range filter, is the usual remedy. The second is the belief that the line rewrites its own past. The widely used public version reads only the current and earlier bars, never later ones, and its turn condition includes the close, so while a bar is still forming, a turn can appear and then vanish if the close fails to confirm it. Once the bar closes, the turn and the line on that bar stay fixed. Reading signals on closed bars, and backtesting the same way, removes the issue; what looks like repainting is the live bar still deciding.

Common ways to use it (concepts)

Turn signal

Trade the confirmed turn

Go long on the bar that closes with the line now below price, and short on the bar that closes with the line now above price. Because the turn already needs the window's average and the close to agree, single-wick spikes are ignored; the signal still benefits from a check that the market is trending at all.

Shelf stop

Trail the stop on the stair steps

After an entry from another rule, use the line as the stop. It moves only when the market prints a new defended low or high, so the stop sits under real structure instead of at a fixed distance, and the flat stretches show where the trend has been tested.

Channel break

Ask for a break beyond the channel

For a stricter reading, act only when the close clears the channel on the far side of the line, or exit a long when a close in an up leg breaks the channel floor. Requiring the move to exceed a volatility-scaled margin screens out turns that barely cross the held level.

Pairing it with other indicator families

HalfTrend names the leg but does not say whether the market is trending at all. The Choppiness Index or ADX can decide when its turns deserve attention: accept them while the market is orderly and directional, and set them aside while it drifts sideways, which is exactly when the line turns back and forth.

Because its line comes from swing structure and its channel from ATR, HalfTrend pairs well with tools that build the trend differently. A Hull moving average gives a smooth slope that can confirm the line's direction, a pairing that appears in shared community scripts. A Donchian Channel breakout can supply entry timing while HalfTrend supplies the side of the market and the exit.

Stacking it with Supertrend or Parabolic SAR adds less than it seems: all three are trailing lines that change sides, and on most bars they agree. Comparing them on the same contract is still worthwhile, because it shows whether that market rewards a structure-based trail, a volatility-based trail or an accelerating one.

In AlphaPrime

In AlphaPrime, HalfTrend is a built-in family of the strategy generator, listed under its own name in the building-block catalogue. The inputs you can adjust are the indicator period, which is the amplitude window described above, the ATR length that sizes the channel, and the channel deviation, which sets the channel's distance from the line in half-ATRs. Some conditions carry a setting of their own, such as a bar count, a number of steps or a window.

The condition types cover the line, its legs and its channel. HalfTrend buy signal and HalfTrend sell signal mark the turns; HalfTrend uptrend and HalfTrend downtrend give the state; close above or below the HalfTrend line or either channel reads where price sits. Others read the staircase itself, such as HalfTrend line steps up, HalfTrend line flat for N bars and HalfTrend up leg outlasts the previous leg. The issues on this page have their own conditions too: HalfTrend uptrend close breaks the channel floor, close crosses above HalfTrend without a turn, HalfTrend armed for a buy, which marks a setup the close has not yet confirmed, and HalfTrend turned at least N times in W bars, a direct measure of chop.

The generator crosses these with momentum, volatility, volume and session families, backtests the candidates on the GPU in parallel and validates them out of sample. You can set the out-of-sample validation thresholds, so you keep only combinations that still hold up on data they have never seen. Combinations that pass can be exported as strategy code for trading platforms, where you can inspect them and keep testing in simulation.

FAQ

Does HalfTrend repaint?

Not on closed bars. The widely used public version reads only the current and earlier bars, never later ones, and needs the close to confirm a turn, so a turn can show up on the live bar and disappear before that bar closes. Once the bar is closed, the line and the turn on it no longer change. Read it, and test it, on closed bars.

What are the best HalfTrend settings?

No single setting suits every contract. The amplitude decides how fast the line steps and turns: a shorter window turns sooner and more often, a longer one rides longer legs and reacts later. The channel settings change the channel's width, not the turns. Compare several settings across different market phases and keep the ones whose behaviour stays similar out of sample.

HalfTrend vs Supertrend: what is the difference?

Both are trailing lines that change sides. Supertrend sets its line at a volatility distance from the middle of the bar, so its gap widens and narrows with ATR. HalfTrend holds the last defended swing low or high and turns only when the window's average moves through that level and the close breaks the previous bar's low or high; volatility only sets the channel around the line.