fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Volume Price Trend

Install and import#

bash
npm install fintech-algorithms
ts
import { volumePriceTrend } from "fintech-algorithms/technical-indicators/volume-indicators/volume-price-trend";

Signature#

volumePriceTrend(close, volume, initial)

Like OBV, but each bar contributes volume scaled by the size of the return rather than only its sign — so a 3% move counts for more than a 0.1% one.

Parameters#

NameTypeNotes
closenumber[]Per-bar closing prices, chronological.
volumenumber[]Per-bar traded volume, aligned index-for-index with the price series.
initialnumberStarting value of the running total.
optional

Returns#

Record<string, (number | null)[]> · length same-as-input

Parallel series: price_return, volume, volume_contribution and vpt.

Warm-up#

The first 1 positions are null. The first bar has no prior close, so no return.

Errors#

  • When the input series are not all the same length — throws RangeError

Complexity: time O(n), space O(n).

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

close
[100.28, 100.686113, 101.200346, 101.789282, 102.408843, 103.010585]

Showing 6 of 120 elements.

volume
[990000, 1066468.036, 1130033.236, 1170141.961, 1180511.26, 1160272.794]

Showing 6 of 120 elements.

Call#

volumePriceTrend(close, volume, initial)

Returns#

object with 4 fields: price_return, volume, volume_contribution, vpt

{
  "price_return": [
    0,
    0.004049790586358245,
    0.005107288231496136,
    0.005819505794970345,
    0.006086701741348411,
    0.005875879292963026
  ],
  "volume": [990000, 1066468.036, 1130033.236, 1170141.961, 1180511.26, 1160272.794],
  "volume_contribution": [
    0,
    4318.972212844767,
    5771.405447422296,
    6809.647922977462,
    7185.419941923407,
    6817.622884452954
  ],
  "vpt": [
    0,
    4318.972212844767,
    10090.377660267062,
    16900.025583244525,
    24085.445525167932,
    30903.068409620886
  ]
}

Other exports#

This module also exports obv, accumulationDistributionLine, chaikinMoneyFlow, moneyFlowIndex, forceIndex. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Volume Price Trend — volume price trend comparison
Volume Price Trend — volume price trend mechanism

Calculation flow#

Calculation flow
flowchart LR
  A["Finalized strictly positive finalized close and nonnegative volume"] --> B["Validate order, alignment, and finite values"]
  B --> C["One-bar return"]
  C --> D["Current volume"]
  D --> E["Return-weighted contribution"]
  E --> F{"History and denominator valid?"}
  F -- "No · short history" --> G["warming-up + reason"]
  F -- "No · no finite scale" --> H["undefined + reason"]
  F -- "Yes" --> I["Cumulative VPT"]
  I --> J["ready + aligned component trace"]
Data-basis reconciliation — Volume Price Trend
flowchart LR
    A["Same instrument and identifier?"] -->|Yes| B["Same venue or consolidated scope?"]
    A -->|No| X["Stop: different measurement"]
    B -->|Yes| C["Same volume unit and bar interval?"]
    B -->|No| X
    C -->|Yes| D["Same session and close policy?"]
    C -->|No| X
    D -->|Yes| E["Same corrections and price-volume adjustment basis?"]
    D -->|No| X
    E -->|Yes| F["Same VPT convention, seed, warm-up, and precision?"]
    E -->|No| X
    F -->|Yes| G["Compare intermediate components"]
    F -->|No| Y["Document convention difference"]
    G --> H["Compare final output"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

  • Price Volume Trend (PVT) — TradingView
  • On Balance Volume (OBV) — TradingView
  • Volume — TradingView
  • Consolidated Tape — U.S. Securities and Exchange Commission, Investor.gov
  • Closing Price — U.S. Securities and Exchange Commission, Investor.gov
  • What is Volume? — CME Group
  • Claim-role ledger
  • Evidence boundary
  • Enhanced claim-to-source map
  • Public evidence boundary

The rest of the Volume Indicators family#