HyperTrend
factor = 5 | slope = 14 | width_percent = 80 Overview
HyperTrend is a trend-envelope indicator built around an adaptive average that reacts to ATR-sized moves. It tracks an internal average, expands or contracts its holding distance with volatility, and then projects upper and lower bands around that average. The output includes both the band structure and a signed trend state so it can be used as either a visual envelope or a direct regime signal.
The `trend` output marks directional bias, while `changed` flags state flips. The `average` line is the center of the structure and `upper` and `lower` are the working envelope boundaries. Candle input defaults to close, but slice input can be provided directly when you want to drive the logic from a custom source series.
Defaults: HyperTrend uses `factor = 5.0`, `slope = 14.0`, `width_percent = 80.0`, an internal ATR period of `200`, and candle source `close`.
Implementation Examples
Compute upper, average, lower, trend, and changed series from OHLC and a driving source.
use vector_ta::indicators::hypertrend::{
hypertrend,
HyperTrendInput,
HyperTrendParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};
let output = hypertrend(
&HyperTrendInput::from_slices(
&high,
&low,
&close,
HyperTrendParams {
factor: Some(5.0),
slope: Some(14.0),
width_percent: Some(80.0),
},
),
)?;
let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let candle_output = hypertrend(
&HyperTrendInput::with_default_candles(&candles),
)?;
println!("{:?}", output.average.last());
println!("{:?}", candle_output.trend.last());API Reference
Input Methods▼
// From candles
HyperTrendInput::from_candles(&Candles, &str, HyperTrendParams) -> HyperTrendInput
// From slices
HyperTrendInput::from_slices(&[f64], &[f64], &[f64], HyperTrendParams) -> HyperTrendInput
// From candles with default parameters and source "close"
HyperTrendInput::with_default_candles(&Candles) -> HyperTrendInputParameters Structure▼
pub struct HyperTrendParams {
pub factor: Option<f64>, // default 5.0
pub slope: Option<f64>, // default 14.0
pub width_percent: Option<f64>, // default 80.0
}Output Structure▼
pub struct HyperTrendOutput {
pub upper: Vec<f64>,
pub average: Vec<f64>,
pub lower: Vec<f64>,
pub trend: Vec<f64>,
pub changed: Vec<f64>,
}Validation, Warmup & NaNs▼
- High, low, and source inputs must all be non-empty, equal in length, finite, and satisfy
high >= low. factor,slope, andwidth_percentmust be valid positive finite values.- Streaming resets on invalid bars and begins from an ATR seeding process that uses an internal ATR period of
200. - Batch mode validates float ranges and rejects unsupported kernels through
InvalidKernelForBatch.
Builder, Streaming & Batch APIs▼
// Builder
HyperTrendBuilder::new()
.factor(f64)
.slope(f64)
.width_percent(f64)
.source(String)
.kernel(Kernel)
.apply(&Candles)
HyperTrendBuilder::new()
.apply_slices(&[f64], &[f64], &[f64])
.into_stream()
// Stream
HyperTrendStream::try_new(HyperTrendParams)
HyperTrendStream::update(f64, f64, f64) -> Option<(f64, f64, f64, f64, f64)>
// Batch
HyperTrendBatchBuilder::new()
.factor_range(f64, f64, f64)
.slope_range(f64, f64, f64)
.width_percent_range(f64, f64, f64)
.kernel(Kernel)
.apply_slices(&[f64], &[f64], &[f64])Error Handling▼
pub enum HyperTrendError {
EmptyInputData,
AllValuesNaN,
LengthMismatch { high: usize, low: usize, source_len: usize },
InvalidFactor { factor: f64 },
InvalidSlope { slope: f64 },
InvalidWidthPercent { width_percent: f64 },
OutputLengthMismatch { expected: usize, got: usize },
InvalidRange { start: String, end: String, step: String },
InvalidFloatRange { start: f64, end: f64, step: f64 },
InvalidKernelForBatch(Kernel),
}Python Bindings
Python exposes a scalar function, a stream class, and a batch sweep. The scalar and stream paths return upper, average, lower, trend, and changed together. Batch returns reshaped matrices for the same fields plus the tested factors, slopes, and width percentages.
import numpy as np
from vector_ta import (
hypertrend,
hypertrend_batch,
HyperTrendStream,
)
high = np.asarray(high_values, dtype=np.float64)
low = np.asarray(low_values, dtype=np.float64)
source = np.asarray(close_values, dtype=np.float64)
upper, average, lower, trend, changed = hypertrend(
high,
low,
source,
factor=5.0,
slope=14.0,
width_percent=80.0,
kernel="auto",
)
stream = HyperTrendStream(factor=5.0, slope=14.0, width_percent=80.0)
print(stream.update(float(high[-1]), float(low[-1]), float(source[-1])))
batch = hypertrend_batch(
high,
low,
source,
factor_range=(4.0, 6.0, 1.0),
slope_range=(10.0, 14.0, 4.0),
width_percent_range=(60.0, 80.0, 20.0),
kernel="auto",
)
print(batch["trend"].shape)
print(batch["width_percents"])JavaScript/WASM Bindings
The WASM layer exposes scalar, batch, and into-buffer helpers. The scalar binding returns `upper`, `average`, `lower`, `trend`, and `changed`. The batch binding returns flattened arrays for those fields, along with combos and matrix dimensions.
import init, {
hypertrend,
hypertrend_batch,
} from "@vectoralpha/vector_ta";
await init();
const single = hypertrend(high, low, source, 5.0, 14.0, 80.0);
console.log(single.average);
console.log(single.trend);
const batch = hypertrend_batch(high, low, source, {
factor_range: [4.0, 6.0, 1.0],
slope_range: [10.0, 14.0, 4.0],
width_percent_range: [60.0, 80.0, 20.0],
});
console.log(batch.rows, batch.cols);
console.log(batch.combos);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)
Related Indicators
Average Directional Index
Technical analysis indicator
Average Directional Movement Index Rating
Technical analysis indicator
Alligator
Technical analysis indicator
Aroon
Technical analysis indicator
Aroon Oscillator
Technical analysis indicator
Chande Momentum Oscillator
Technical analysis indicator