High–Low Pearson Correlation (CORREL_HL)
period = 9 Overview
The High Low Pearson Correlation (CORREL_HL) measures the statistical relationship between high and low prices over a rolling window using the Pearson correlation coefficient. This indicator quantifies how closely the high and low prices move together, producing values between negative 1 and positive 1. A correlation near 1 indicates that highs and lows move in perfect tandem, while values near negative 1 suggest inverse relationships. The calculation uses the standard Pearson formula, computing the covariance between highs and lows divided by the product of their standard deviations.
CORREL_HL provides insights into market volatility patterns and price range behavior. High positive correlations typically occur during trending markets where highs and lows expand or contract together. Lower correlations may indicate choppy or transitional market conditions where the relationship between daily highs and lows becomes less predictable. Values approaching zero suggest no linear relationship between the high and low price movements. The indicator helps traders assess whether price ranges are expanding, contracting, or behaving erratically.
Traders use CORREL_HL to identify changes in market character and volatility regimes. Sudden drops in correlation often precede breakouts or significant market moves as the normal price range relationships break down. The indicator also helps in risk management by signaling when market behavior deviates from typical patterns. Some trading systems use CORREL_HL as a filter, adjusting position sizes or strategies based on the strength of the high low correlation. When combined with other volatility measures like ATR or Bollinger Band width, it provides a comprehensive view of market dynamics.
Implementation Examples
Compute CORREL_HL from slices or candles:
use vectorta::indicators::correl_hl::{correl_hl, CorrelHlInput, CorrelHlParams};
use vectorta::utilities::data_loader::{Candles, read_candles_from_csv};
// Using with high/low slices
let high = vec![101.0, 103.0, 102.5, 104.0];
let low = vec![ 99.0, 100.5, 101.0, 102.0];
let params = CorrelHlParams { period: Some(9) }; // default=9
let input = CorrelHlInput::from_slices(&high, &low, params);
let result = correl_hl(&input)?;
// Using with Candles (selects high/low internally), defaults period=9
let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let input = CorrelHlInput::with_default_candles(&candles);
let result = correl_hl(&input)?;
// Access values (NaN during warmup)
for v in result.values { println!("r: {}", v); } API Reference
Input Methods ▼
// From high/low slices
CorrelHlInput::from_slices(&[f64], &[f64], CorrelHlParams) -> CorrelHlInput
// From candles (selects high/low internally)
CorrelHlInput::from_candles(&Candles, CorrelHlParams) -> CorrelHlInput
// From candles with default params
CorrelHlInput::with_default_candles(&Candles) -> CorrelHlInput Parameters Structure ▼
pub struct CorrelHlParams {
pub period: Option<usize>, // Default: 9
} Output Structure ▼
pub struct CorrelHlOutput {
pub values: Vec<f64>, // Pearson correlation per index
} Validation, Warmup & NaNs ▼
period > 0andperiod ≤ len; otherwiseCorrelHlError::InvalidPeriod.highandlowmust have equal length; otherwiseCorrelHlError::DataLengthMismatch.- Warmup: indices before
first_valid + period − 1areNaN. - Windows containing any
NaNyieldNaNoutputs; if either window variance is zero, output is0.0. - On candle input, missing fields raise
CorrelHlError::CandleFieldError.
Error Handling ▼
use vectorta::indicators::correl_hl::CorrelHlError;
match correl_hl(&input) {
Ok(output) => process(output.values),
Err(CorrelHlError::EmptyData) => eprintln!("Empty high/low data"),
Err(CorrelHlError::InvalidPeriod { period, data_len }) =>
eprintln!("Invalid period {} for length {}", period, data_len),
Err(CorrelHlError::DataLengthMismatch) => eprintln!("high/low length mismatch"),
Err(CorrelHlError::NotEnoughValidData { needed, valid }) =>
eprintln!("Need {} points after first valid, have {}", needed, valid),
Err(CorrelHlError::AllValuesNaN) => eprintln!("All values are NaN"),
Err(CorrelHlError::CandleFieldError { field }) => eprintln!("Missing candle field: {}", field),
Err(CorrelHlError::OutputLengthMismatch { dst, src }) =>
eprintln!("Output length {} != input length {}", dst, src),
} Python Bindings
Basic Usage ▼
Calculate CORREL_HL using NumPy arrays:
import numpy as np
from vectorta import correl_hl
high = np.array([101.0, 103.0, 102.5, 104.0], dtype=float)
low = np.array([ 99.0, 100.5, 101.0, 102.0], dtype=float)
# period is required; kernel is optional ("auto", "avx2", "avx512", ...)
result = correl_hl(high, low, period=9, kernel="auto")
print(result) # NumPy array of r values (NaN during warmup) Streaming Real-time Updates ▼
from vectorta import CorrelHlStream
stream = CorrelHlStream(period=9)
for h, l in zip(high_series, low_series):
r = stream.update(h, l)
if r is not None:
print("corr:", r) Batch Parameter Sweep ▼
import numpy as np
from vectorta import correl_hl_batch
high = np.array([...], dtype=float)
low = np.array([...], dtype=float)
res = correl_hl_batch(high, low, period_range=(5, 30, 5), kernel="auto")
# res['values']: shape [rows, len]
# res['periods']: tested periods
print(res['periods']) CUDA Acceleration ▼
CUDA support for CORREL_HL is coming soon.
JavaScript/WASM Bindings
Basic Usage ▼
Calculate CORREL_HL in JavaScript/TypeScript:
import { correl_hl_js } from 'vectorta-wasm';
const high = new Float64Array([/* ... */]);
const low = new Float64Array([/* ... */]);
const result = correl_hl_js(high, low, 9); // period=9
console.log('r values:', result); Memory-Efficient Operations ▼
Use zero-copy operations for better performance with large datasets:
import { correl_hl_alloc, correl_hl_free, correl_hl_into, memory } from 'vectorta-wasm';
const length = 10_000;
const high = new Float64Array(length);
const low = new Float64Array(length);
// ... fill arrays ...
const highPtr = correl_hl_alloc(length);
const lowPtr = correl_hl_alloc(length);
const outPtr = correl_hl_alloc(length);
new Float64Array(memory.buffer, highPtr, length).set(high);
new Float64Array(memory.buffer, lowPtr, length).set(low);
// Write results directly into WASM memory
correl_hl_into(highPtr, lowPtr, outPtr, length, 9);
const out = new Float64Array(memory.buffer, outPtr, length).slice();
correl_hl_free(highPtr, length);
correl_hl_free(lowPtr, length);
correl_hl_free(outPtr, length);
console.log('r:', out); Batch Processing ▼
Test multiple period values efficiently:
import { correl_hl_batch } from 'vectorta-wasm';
const high = new Float64Array([/* ... */]);
const low = new Float64Array([/* ... */]);
// Define period range {start, end, step}
const res = correl_hl_batch(high, low, { period_range: [5, 30, 5] });
// res = { values: Float64Array, periods: number[], rows, cols }
console.log(res.periods); Performance Analysis
AMD Ryzen 9 9950X (CPU) | NVIDIA RTX 4090 (GPU) | Benchmarks: 2026-01-05
Related Indicators
Correlation Cycle
Technical analysis indicator
Deviation
Technical analysis indicator
Ehlers Error-Correcting EMA (ECEMA)
Moving average indicator
Ehlers Instantaneous Trendline
Moving average indicator
Ehlers Kaufman Adaptive Moving Average
Moving average indicator
Ehlers Pma
Technical analysis indicator