Skip to content
All library documents

Calculating On-Balance Volume with an MQL5 Ring Buffer

Article MQL5 code base

Summary

This MQL5 programming reference describes a class that calculates On-Balance Volume (OBV) in a ring buffer. The initialization method accepts an optional period, buffer size, and indexing mode. With the default period, OBV accumulates across the chart’s bars; a positive period instead limits the calculation to a specified number of bars, following a moving-average-style window. The class processes price and volume arrays or individual bar values and provides access to the resulting series and basic indicator metadata.

The examples show how to update the calculation in an indicator routine and copy values from the ring buffer into a chart buffer. They also describe drawing a second OBV series based on the first. The reference notes that ring-buffer indexing matches time-series indexing. It explains implementation and integration, but provides no trading rules, empirical evaluation, or evidence that a particular OBV period or signal is profitable. The associated ring-buffer class is required for use.

Key ideas

  • The class computes OBV from price and volume data using a ring buffer.
  • A zero period accumulates values across the chart, while a positive period limits the calculation window.
  • The class accepts either complete arrays or individual price and volume observations.
  • Ring-buffer indexing is described as matching the indexing of a time series.
  • The examples cover indicator integration and a second OBV calculation, without testing trading performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.