Trend Direction Force Index
length = 10 Overview
Trend Direction Force Index turns recent directional persistence into a single force line. Instead of splitting bullish and bearish continuation into two separate outputs, it collapses the current directional pressure into one series that can be used as a compact confirmation tool for momentum, breakout follow-through, or trend exhaustion studies.
In VectorTA the indicator accepts a direct source slice or candle data with an explicit source field, supports a streaming update path for live bars, and exposes batch sweeps across its single length control. It is one of the simpler interfaces in the library, but that simplicity makes it useful when you want a lightweight force measure rather than a full multi-line trend panel.
Defaults: `length = 10`.
Implementation Examples
Run the force index on a direct source slice or on candle data.
use vector_ta::indicators::trend_direction_force_index::{
trend_direction_force_index,
TrendDirectionForceIndexInput,
TrendDirectionForceIndexParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};
let direct = trend_direction_force_index(&TrendDirectionForceIndexInput::from_slice(
&close,
TrendDirectionForceIndexParams { length: Some(10) },
))?;
let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let from_candles = trend_direction_force_index(
&TrendDirectionForceIndexInput::with_default_candles(&candles),
)?;
println!("force = {:?}", direct.values.last());
println!("candle force = {:?}", from_candles.values.last());API Reference
Input Methods▼
TrendDirectionForceIndexInput::from_candles(&Candles, "close", TrendDirectionForceIndexParams)
-> TrendDirectionForceIndexInput
TrendDirectionForceIndexInput::from_slice(&[f64], TrendDirectionForceIndexParams)
-> TrendDirectionForceIndexInput
TrendDirectionForceIndexInput::with_default_candles(&Candles)
-> TrendDirectionForceIndexInputParameters Structure▼
pub struct TrendDirectionForceIndexParams {
pub length: Option<usize>, // default 10
}Output Structure▼
pub struct TrendDirectionForceIndexOutput {
pub values: Vec<f64>,
}Validation, Warmup & NaNs▼
- The source slice must not be empty or entirely NaN, and the resolved
lengthmust fit the available data. - Direct evaluation rejects output-length mismatches and invalid inputs before producing the force series.
- The stream returns
Noneuntil enough valid values accumulate to compute the force line. - Batch mode validates the length axis and rejects invalid sweep ranges.
Builder, Streaming & Batch APIs▼
TrendDirectionForceIndexBuilder::new()
.length(usize)
.kernel(Kernel)
.apply(&Candles)
.apply_candles(&Candles, "hlc3")
.apply_slice(&[f64])
.into_stream()
TrendDirectionForceIndexStream::try_new(params)
stream.update(value) -> Option<f64>
TrendDirectionForceIndexBatchBuilder::new()
.length_range(start, end, step)
.apply_slice(&[f64])Python Bindings
Python exposes a direct function, a stream class, and a batch helper that returns the force matrix plus the resolved length axis.
from vector_ta import (
trend_direction_force_index,
trend_direction_force_index_batch,
TrendDirectionForceIndexStream,
)
values = trend_direction_force_index(close, length=10)
stream = TrendDirectionForceIndexStream(length=10)
point = stream.update(close[-1])
batch = trend_direction_force_index_batch(close, length_range=(6, 18, 2))JavaScript/WASM Bindings
The WASM layer exposes direct, batch, and into-buffer entry points for callers that want either a simple object-returning path or manual memory control.
import init, {
trend_direction_force_index_js,
trend_direction_force_index_batch_js,
trend_direction_force_index_alloc,
trend_direction_force_index_free,
trend_direction_force_index_into,
trend_direction_force_index_batch_into,
} from "vector-ta-wasm";
await init();
const single = trend_direction_force_index_js(close, 10);
console.log(single.values);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)