# On-Balance Volume (OBV)

`D07-F05-A01` · Technical Indicators → Volume Indicators · archetype `series-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/volume-indicators/obv/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { obv } from "fintech-algorithms/technical-indicators/volume-indicators/obv";
```

## Signature

```ts
obv(close, volume, initial)
```

On-balance volume: a running total that adds the bar's volume when price closed up and subtracts it when price closed down. The level is arbitrary; only its direction carries information.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `close` | `number[]` | yes | Per-bar closing prices, chronological. |
| `volume` | `number[]` | yes | Per-bar traded volume, aligned index-for-index with the price series. |
| `initial` | `number` | no | Starting value of the running total. Only affects the level, never the shape. · default: 0 |

## Returns

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

Parallel series: `direction`, `volume`, `signed_volume` and the running `obv`.

## Warm-up

The first `0` positions are `not applicable — no position is null`. The first bar has no prior close, so its direction is 0 and the running total starts at `initial`. Those are defined values rather than warm-up nulls, so every position of every returned series is populated.

## Errors

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

## Complexity

Time `O(n)`, space `O(n)`.

## Worked example

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`:

```json
[100.28, 100.686113, 101.200346, 101.789282, 102.408843, 103.010585]
```

Showing 6 of 120 elements.

`volume`:

```json
[990000, 1066468.036, 1130033.236, 1170141.961, 1180511.26, 1160272.794]
```

Showing 6 of 120 elements.

### Call

```ts
obv(close, volume, initial)
```

### Returns

object with 4 fields: direction, volume, signed_volume, obv

```json
{
  "direction": [0, 1, 1, 1, 1, 1],
  "volume": [990000, 1066468.036, 1130033.236, 1170141.961, 1180511.26, 1160272.794],
  "signed_volume": [0, 1066468.036, 1130033.236, 1170141.961, 1180511.26, 1160272.794],
  "obv": [0, 1066468.036, 2196501.272, 3366643.233, 4547154.493, 5707427.287]
}
```

## Other exports

`accumulationDistributionLine`, `chaikinMoneyFlow`, `moneyFlowIndex`, `volumePriceTrend`, `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.

## Verification and provenance

Tier: **verified** (via scenario-fixture).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/technical-indicators/volume-indicators/obv/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/volume-indicators/obv/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
