Skip to content
All library documents

Calculating Fractals with an MQL5 Ring Buffer

Article MQL5 code base

Summary

This document describes an MQL5 class for calculating and accessing upper and lower Bill Williams fractals using a ring buffer. A fractal is identified around a price extremum by comparing bars on either side; the class lets users set how many bars to inspect on each side, the buffer size, and the indexing convention. It offers methods to calculate from high and low price arrays or process individual values, alongside accessors for the resulting series and required history.

The examples show how to initialize the class, update it during indicator calculation, and copy its upper and lower fractal values into output buffers. They also demonstrate applying the calculation to price data or to another indicator's output. The document explains the interface and integration pattern, but gives no trading rules, tests, or performance results. Because a fractal needs bars to the right of its extremum, its identification depends on subsequent data and is therefore delayed; the class description does not discuss signal handling or trading use.

Key ideas

  • The class calculates upper and lower fractals from high and low series using a ring buffer.
  • Users can configure the number of bars on each side of an extremum and the buffer size.
  • Calculation can process whole arrays or individual values.
  • A fractal requires bars to the right of its extremum, so identification is delayed until those bars exist.

Tags

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