Vertical Horizontal Filter
length = Overview
Vertical Horizontal Filter is a single-line market-mode study that compares directional movement with total path length over a rolling window. It is commonly used to distinguish trend persistence from noisier sideways behavior without bringing in multiple smoothing or signal lines.
In VectorTA the indicator works on a direct source slice or on candles, supports streaming updates, and exposes a single-axis batch sweep over its lookback. That makes it one of the lighter-weight regime filters in the library and a useful companion to trend-following systems.
Defaults: `length = 28`.
Implementation Examples
Run VHF on a source slice or on candles using the default configuration.
use vector_ta::indicators::vertical_horizontal_filter::{
vertical_horizontal_filter,
VerticalHorizontalFilterInput,
VerticalHorizontalFilterParams,
};
let output = vertical_horizontal_filter(&VerticalHorizontalFilterInput::from_slice(
&close,
VerticalHorizontalFilterParams { length: Some(28) },
))?;
println!("vhf = {:?}", output.values.last());API Reference
Input Methods ▼
VerticalHorizontalFilterInput::from_candles(&Candles, VerticalHorizontalFilterParams)
-> VerticalHorizontalFilterInput
VerticalHorizontalFilterInput::from_slice(&[f64], VerticalHorizontalFilterParams)
-> VerticalHorizontalFilterInput
VerticalHorizontalFilterInput::with_default_candles(&Candles)
-> VerticalHorizontalFilterInputParameters Structure ▼
pub struct VerticalHorizontalFilterParams {
pub length: Option<usize>,
}Output Structure ▼
pub struct VerticalHorizontalFilterOutput {
pub values: Vec<f64>,
}Validation, Warmup & NaNs ▼
- The source slice must contain enough valid data for the resolved
length. - Candles follow the library standard input path, while slices expose the leanest direct route.
- Streaming returns
Noneuntil the lookback is fully warmed up. - Batch mode validates the single range axis before building the output matrix.
Builder, Streaming & Batch APIs ▼
VerticalHorizontalFilterBuilder::new()
.length(usize)
.kernel(Kernel)
.apply(&Candles)
.apply_slice(&[f64])
.into_stream()
VerticalHorizontalFilterStream::try_new(params)
stream.update(value) -> Option<f64>
VerticalHorizontalFilterBatchBuilder::new()
.length_range(start, end, step)
.apply_slice(&[f64])Python Bindings
Python exposes direct, stream, and batch helpers for the single VHF line.
from vector_ta import vertical_horizontal_filter, vertical_horizontal_filter_batch, VerticalHorizontalFilterStream
single = vertical_horizontal_filter(close, length=28)
stream = VerticalHorizontalFilterStream(length=28)
point = stream.update(close[-1])
batch = vertical_horizontal_filter_batch(close, length_range=(14, 42, 7))JavaScript/WASM Bindings
The WASM layer exposes direct, batch, allocation, and into-buffer helpers for VHF calculations.
import init, { vertical_horizontal_filter_js, vertical_horizontal_filter_batch_js } from "vector-ta-wasm";
await init();
const single = vertical_horizontal_filter_js(close, 28);
const batch = vertical_horizontal_filter_batch_js(close, { length_range: [14, 42, 7] });CUDA Bindings (Rust)
Additional details for the CUDA bindings can be found inside the VectorTA repository.
Performance Analysis
Across sizes, Rust CPU runs about 1.14× faster than Tulip C in this benchmark.
AMD Ryzen 9 9950X (CPU) | NVIDIA RTX 4090 (GPU)