Twiggs Money Flow

Parameters: length = 21 | smoothing_length = 14 | ma_type = WMA

Overview

Twiggs Money Flow is a two-line money-flow study that tracks the raw TMF series and a smoothed companion line from the same high-low-close-volume input. It is useful when you want one momentum-style measure tied to volume participation, but still want a second line for confirmation or crossover analysis.

In VectorTA the indicator works on HLCV slices or candle data, supports a configurable smoothing stage and moving-average family, streams one bar at a time, and exposes batch sweeps across the lookback and smoothing lengths. That makes it practical for both chart overlays and parameter studies on money-flow persistence.

Defaults: `length = 21`, `smoothing_length = 14`, and `ma_type = "WMA"`.

Implementation Examples

Run Twiggs Money Flow on direct HLCV slices or on candles with the default settings.

use vector_ta::indicators::twiggs_money_flow::{
    twiggs_money_flow,
    TwiggsMoneyFlowInput,
    TwiggsMoneyFlowParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};

let direct = twiggs_money_flow(&TwiggsMoneyFlowInput::from_slices(
    &high,
    &low,
    &close,
    &volume,
    TwiggsMoneyFlowParams {
        length: Some(21),
        smoothing_length: Some(14),
        ma_type: Some("WMA".to_string()),
    },
))?;

let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let from_candles = twiggs_money_flow(&TwiggsMoneyFlowInput::with_default_candles(&candles))?;

println!("tmf = {:?}", direct.tmf.last());
println!("smoothed = {:?}", from_candles.smoothed.last());

API Reference

Input Methods
TwiggsMoneyFlowInput::from_candles(&Candles, TwiggsMoneyFlowParams)
    -> TwiggsMoneyFlowInput

TwiggsMoneyFlowInput::from_slices(&[f64], &[f64], &[f64], &[f64], TwiggsMoneyFlowParams)
    -> TwiggsMoneyFlowInput

TwiggsMoneyFlowInput::with_default_candles(&Candles)
    -> TwiggsMoneyFlowInput
Parameters Structure
pub struct TwiggsMoneyFlowParams {
    pub length: Option<usize>,
    pub smoothing_length: Option<usize>,
    pub ma_type: Option<String>,
}
Output Structure
pub struct TwiggsMoneyFlowOutput {
    pub tmf: Vec<f64>,
    pub smoothed: Vec<f64>,
}
Validation, Warmup & NaNs
  • High, low, close, and volume inputs must share the same non-zero length and contain enough valid data to cover the resolved length and smoothing_length.
  • The moving-average type must be one of the supported weighted families accepted by the Rust implementation.
  • Streaming returns None until the warmup for both the TMF core and the smoothing stage is complete.
  • Batch mode validates both range axes and rejects invalid batch kernels.
Builder, Streaming & Batch APIs
TwiggsMoneyFlowBuilder::new()
    .length(usize)
    .smoothing_length(usize)
    .ma_type("WMA")
    .kernel(Kernel)
    .apply(&Candles)
    .apply_slices(&[f64], &[f64], &[f64], &[f64])
    .into_stream()

TwiggsMoneyFlowStream::try_new(params)
stream.update(high, low, close, volume) -> Option<(f64, f64)>

TwiggsMoneyFlowBatchBuilder::new()
    .length_range(start, end, step)
    .smoothing_length_range(start, end, step)
    .apply_slices(&[f64], &[f64], &[f64], &[f64])

Python Bindings

Python exposes a dictionary-returning function, a stream class, and a batch helper that reshapes both the TMF and smoothed outputs.

from vector_ta import twiggs_money_flow, twiggs_money_flow_batch, TwiggsMoneyFlowStream

single = twiggs_money_flow(
    high,
    low,
    close,
    volume,
    length=21,
    smoothing_length=14,
    ma_type="WMA",
)

stream = TwiggsMoneyFlowStream(length=21, smoothing_length=14, ma_type="WMA")
point = stream.update(high[-1], low[-1], close[-1], volume[-1])

batch = twiggs_money_flow_batch(
    high,
    low,
    close,
    volume,
    length_range=(13, 34, 3),
    smoothing_length_range=(7, 21, 2),
    ma_type="WMA",
)

JavaScript/WASM Bindings

The WASM layer exposes direct, batch, allocation, and into-buffer helpers for HLCV workflows.

import init, {
  twiggs_money_flow_js,
  twiggs_money_flow_batch_js,
  twiggs_money_flow_alloc,
  twiggs_money_flow_free,
  twiggs_money_flow_into,
  twiggs_money_flow_into_host,
  twiggs_money_flow_batch_into,
} from "vector-ta-wasm";

await init();

const single = twiggs_money_flow_js(high, low, close, volume, 21, 14, "WMA");
const batch = twiggs_money_flow_batch_js(high, low, close, volume, {
  length_range: [13, 34, 3],
  smoothing_length_range: [7, 21, 2],
  ma_type: "WMA",
});

CUDA Bindings (Rust)

Additional details for the CUDA bindings can be found inside the VectorTA repository.

Performance Analysis

Comparison:
View:
Placeholder data (no recorded benchmarks for this indicator)

Across sizes, Rust CPU runs about 1.14× faster than Tulip C in this benchmark.

Loading chart...

AMD Ryzen 9 9950X (CPU) | NVIDIA RTX 4090 (GPU)

Related Indicators