Supertrend Recovery
atr_length = 10 | multiplier = 3 | alpha_percent = 5 | threshold_atr = 1 Overview
Supertrend Recovery extends a SuperTrend-style band model with extra state that focuses on recovery behavior after a directional switch. Instead of only emitting a band value, it also returns the price level where the latest switch occurred, a trend-state series, and a change marker so you can analyze whether a new move is stabilizing or merely whipsawing around the recovery threshold.
In VectorTA the indicator works on explicit high, low, and close slices or on candle data, supports a streaming update path for live bars, and exposes batch sweeps across the ATR lookback, the volatility multiplier, the recovery alpha percentage, and the ATR threshold control. That makes it suitable for testing how strict or loose a SuperTrend recovery regime should be under different volatility conditions.
Defaults: `atr_length = 10`, `multiplier = 3.0`, `alpha_percent = 5.0`, and `threshold_atr = 1.0`.
Implementation Examples
Compute the recovery band from direct HLC slices or from candle data.
use vector_ta::indicators::supertrend_recovery::{
supertrend_recovery,
SuperTrendRecoveryInput,
SuperTrendRecoveryParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};
let direct = supertrend_recovery(&SuperTrendRecoveryInput::from_slices(
&high,
&low,
&close,
SuperTrendRecoveryParams {
atr_length: Some(10),
multiplier: Some(3.0),
alpha_percent: Some(5.0),
threshold_atr: Some(1.0),
},
))?;
let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let from_candles = supertrend_recovery(
&SuperTrendRecoveryInput::with_default_candles(&candles),
)?;
println!("band = {:?}", direct.band.last());
println!("switch = {:?}", direct.switch_price.last());
println!("trend = {:?}", direct.trend.last());
println!("changed = {:?}", direct.changed.last()); API Reference
Input Methods ▼
SuperTrendRecoveryInput::from_candles(&Candles, SuperTrendRecoveryParams)
-> SuperTrendRecoveryInput
SuperTrendRecoveryInput::from_slices(&[f64], &[f64], &[f64], SuperTrendRecoveryParams)
-> SuperTrendRecoveryInput
SuperTrendRecoveryInput::with_default_candles(&Candles)
-> SuperTrendRecoveryInputParameters Structure ▼
pub struct SuperTrendRecoveryParams {
pub atr_length: Option<usize>, // default 10
pub multiplier: Option<f64>, // default 3.0
pub alpha_percent: Option<f64>, // default 5.0
pub threshold_atr: Option<f64>, // default 1.0
}Output Structure ▼
pub struct SuperTrendRecoveryOutput {
pub band: Vec<f64>,
pub switch_price: Vec<f64>,
pub trend: Vec<f64>,
pub changed: Vec<f64>,
}Validation, Thresholds & NaNs ▼
high,low, andclosemust have matching lengths and enough valid bars for the resolved ATR lookback.atr_lengthmust fit the available data, and the three float controls must each satisfy their documented validation rules.- Direct evaluation rejects empty input, all-NaN input, and output-length mismatches.
- The stream returns
Noneuntil enough valid bars accumulate to seed the recovery band state. - Batch mode validates all integer and float sweep ranges and rejects non-batch kernels.
Builder, Streaming & Batch APIs ▼
SuperTrendRecoveryBuilder::new()
.atr_length(usize)
.multiplier(f64)
.alpha_percent(f64)
.threshold_atr(f64)
.kernel(Kernel)
.apply(&Candles)
.apply_slices(&[f64], &[f64], &[f64])
.into_stream()
SuperTrendRecoveryStream::try_new(params)
stream.update(high, low, close) -> Option<(f64, f64, f64, f64)>
SuperTrendRecoveryBatchBuilder::new()
.atr_length_range(start, end, step)
.multiplier_range(start, end, step)
.alpha_percent_range(start, end, step)
.threshold_atr_range(start, end, step)
.kernel(Kernel)
.apply(&Candles)
.apply_slices(&[f64], &[f64], &[f64])Python Bindings
Python exposes a direct function, a stream class, and a batch helper that returns band, switch-price, trend, and changed matrices plus the resolved recovery axes.
from vector_ta import (
supertrend_recovery,
supertrend_recovery_batch,
SuperTrendRecoveryStream,
)
band, switch_price, trend, changed = supertrend_recovery(
high,
low,
close,
atr_length=10,
multiplier=3.0,
alpha_percent=5.0,
threshold_atr=1.0,
)
stream = SuperTrendRecoveryStream(
atr_length=10,
multiplier=3.0,
alpha_percent=5.0,
threshold_atr=1.0,
)
point = stream.update(high[-1], low[-1], close[-1])
batch = supertrend_recovery_batch(
high,
low,
close,
atr_length_range=(8, 12, 2),
multiplier_range=(2.0, 3.5, 0.5),
alpha_percent_range=(3.0, 6.0, 1.0),
threshold_atr_range=(0.5, 1.5, 0.5),
)JavaScript/WASM Bindings
The WASM layer exposes a direct object-returning call, a batch helper, and low-level allocation and into-buffer APIs for caller-managed memory.
import init, {
supertrend_recovery_js,
supertrend_recovery_alloc,
supertrend_recovery_free,
supertrend_recovery_into,
supertrend_recovery_batch_into,
} from "vector-ta-wasm";
await init();
const single = supertrend_recovery_js(high, low, close, 10, 3.0, 5.0, 1.0);
console.log(single.band, single.switch_price, single.trend, single.changed);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