PINE LIBRARY

LibVolm

68
Library "LibVolm"
This library provides a collection of core functions for volume and
money flow analysis. It offers implementations of several classic
volume-based indicators, with a focus on flexibility
for applications like multi-timeframe and session-based analysis.

Key Features:

1. **Suite of Classic Volume Indicators:** Includes standard
implementations of several foundational indicators:
- **On Balance Volume (`obv`):** A momentum indicator that
accumulates volume based on price direction.
- **Accumulation/Distribution Line (`adLine`):** Measures cumulative
money flow using the close's position within the bar's range.
- **Chaikin Money Flow (`cmf`):** An oscillator version of the ADL
that measures money flow over a specified lookback period.

2. **Anchored/Resettable Indicators:** The library includes flexible,
resettable indicators ideal for cyclical analysis:
- **Anchored VWAP (`vwap`):** Calculates a Volume Weighted Average
Price that can be reset on any user-defined `reset` condition.
It returns both the VWAP and the number of bars (`prdBars`) in
the current period.
- **Resettable CVD (`cvd`):** Computes a Cumulative Volume Delta
that can be reset on a custom `reset` anchor. The function
also tracks and returns the highest (`hi`) and lowest (`lo`)
delta values reached within the current period.
(Note: The delta sign is determined by a specific logic:
it first checks close vs. open, then close vs. prior
close, and persists the last non-zero sign).

3. **Volume Sanitization:** All functions that use the built-in
`volume` variable automatically sanitize it via an internal
function. This process replaces `na` values with 0 and ensures
no negative volume values are used, providing stable calculations.

---

**DISCLAIMER**

This library is provided "AS IS" and for informational and
educational purposes only. It does not constitute financial,
investment, or trading advice.

The author assumes no liability for any errors, inaccuracies,
or omissions in the code. Using this library to build
trading indicators or strategies is entirely at your own risk.

As a developer using this library, you are solely responsible
for the rigorous testing, validation, and performance of any
scripts you create based on these functions. The author shall
not be held liable for any financial losses incurred directly
or indirectly from the use of this library or any scripts
derived from it.

obv(price)
  Calculates the On Balance Volume (OBV) cumulative indicator.
  Parameters:
    price (float): series float Source price series, typically the close.
  Returns: series float Cumulative OBV value.

adLine()
  Computes the Accumulation/Distribution Line (AD Line).
  Returns: series float Cumulative AD Line value.

cmf(length)
  Computes Chaikin Money Flow (CMF).
  Parameters:
    length (int): series int Lookback length for the CMF calculation.
  Returns: series float CMF value.

vwap(price, reset)
  Calculates an anchored Volume Weighted Average Price (VWAP).
  Parameters:
    price (float): series float Source price series (usually *close*).
    reset (bool): series bool A signal that is *true* on the bar where the
accumulation should be reset.
  Returns: [vwap, prdBars]
vwap series float The calculated Volume Weighted Average Price for the current period.
prdBars series int The number of bars that have passed since the last reset.

cvd(reset)
  Calculates a resettable, cumulative Volume Delta (CVD).
It accumulates volume delta and tracks its high/low range. The
accumulation is reset to zero whenever the `reset` condition is true.
This is useful for session-based analysis, intra-bar calculations,
or any other custom-anchored accumulation.
  Parameters:
    reset (bool): series bool A signal that is *true* on the bar where the
accumulation should be reset.
  Returns: [cum, hi, lo]
cum series float The current cumulative volume delta.
hi series float The highest peak the cumulative delta has reached in the current period.
lo series float The lowest trough the cumulative delta has reached in the current period.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.