Skip to content
All library documents

Handling Meaningful Data Offsets When Applying Indicators to Indicators

Article MQL5 articles

Summary

This article explains how to calculate a custom indicator from another indicator’s output in MQL5. Its example applies a True Strength Index calculation to RSI data and shows why the result can be missing or incorrect if the receiving indicator assumes valid input begins at the first array element. The OnCalculate begin parameter identifies the first meaningful input position; earlier buffer entries may contain EMPTY_VALUE, a large sentinel value, rather than usable observations.

The article shows how to use begin to skip invalid values, shift initialization and smoothing positions, and adjust the plot’s drawing start. It also explains that the dependent indicator’s unavailable warm-up region adds to the source indicator’s own drawing offset. The example derives a combined start position for TSI applied to RSI and recommends explicitly setting buffer values, including empty ones, rather than relying on one-time initialization. This is implementation guidance for MQL5 indicators, not evidence of a trading signal’s predictive value; correct offsets still depend on the source indicator’s buffer and plotting behavior.

Key ideas

  • The begin argument marks the first meaningful value when an indicator consumes another indicator’s buffer.
  • Values before begin can be EMPTY_VALUE and should not enter calculations.
  • Calculation loops and dependent buffers need to account for the input offset.
  • The plot start for a chained indicator combines the source and custom indicator warm-up positions.
  • Indicator buffers should be set consistently, including entries that represent missing values.

Tags

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