Investment Studio > Expressions > Functions > Indicator > VHF

float array[*][2] vhf(float array[*][2] dc, integer days)

Returns a two-column array containing dates (first column) and corresponding Vertical/Horizontal Filter (VHF) values (second column). Given n input rows in dc, n - days (or fewer) rows are returned.

dc is a two-column array containing dates (first column) and corresponding daily closes (second column). The array is assumed to be time-sorted, with earlier dates preceding later dates.

Automatic type conversion allows the use of date strings as arguments instead of explicit date values.

days sets the time frame of the VHF, i.e. the number of trading days over which each day's VHF is computed. A popular value is 28.

Interpretation

VHF is a trend strength indicator. It's defined as the ratio between the price range (highest close - lowest close) and the sum of absolute day to day price moves, i.e. of abs(close - previous close) in the time frame under study. The higher the value, the stronger the trend, regardless of direction.

The lack of normalization (different time frames can be expected to yield different typical values) makes it hard to define general rules based on specific threshold levels, as for ADX. Such levels must instead be determined from historical data, using the chosen time frame. In practice, there are three common applications of VHF:

As a condition of applicability for other indicators. Some indicators, like EMA and MACD, work best in wide-swinging markets. Others, like RSI and STO, work best in tighter trading ranges. A historically high VHF value would lend more credibility to the former kind of indicators, a historically low VHF value to the latter.
As a tool for momentum investing: buy (or go short, depending on trend direction) on rising VHF, sell (or cover your shorts) when it starts declining.
As a contrarian alert: expect a consolidation phase to follow when the VHF hits historically high levels, expect a new trend to emerge when the VHF hits historically low levels. A tenet of classic technical analysis worth keeping in mind in the latter case is that the longer price keeps moving sideways (resulting in a low VHF reading) the more likely it is to reverse the previous trend when it finally breaks out of its consolidation range.

For a real life example, consider the NASDAQ Composite in 2001:

The top chart shows prices in standard candlestick form, the bottom chart shows the corresponding 28 day VHF. You may want to compare this chart and the corresponding MACD chart.

Example

Assuming standard US date format settings,

=vhf({{"1/1/1990", 12}, {"1/2/1990", 11}, {"1/3/1990", 12}}, 2)

returns {{32876, 0.5}}. 32876 is the date code for 1/3/1990; 0.5 is the 2 day VHF computed for that date: the price range is 12 - 11 = 1, the sum of absolute day to day moves is abs(12 - 11) + abs(11 - 12) = 2, so their ratio is 1 / 2 = 0.5.

See also adx, adxr, aro, di, dim, dip, ema, rsi, tsi.