Skip to content
All library documents

Converting Indicator Calculations into Reusable Expert Advisor Functions

Article MQL5 articles

Summary

The article explains how to move indicator calculations into a custom function that an Expert Advisor can call, instead of retrieving values through a custom indicator interface. Its proposed function accepts symbol, timeframe, indicator parameters, and arrays passed by reference for output and intermediate values. It returns a success flag when enough chart history is available and can skip recalculating the current, unfinished bar to reduce work.

The discussion gives general steps for adapting an indicator’s calculation routine, managing buffers and bar indexing, and using the resulting function from an EA. It then describes comparing the custom function’s outputs with those from the original indicator in a strategy tester; the reported differences are zero for the tested RAVI values. This demonstrates equivalence in that example, not correctness for every indicator or configuration. The focus is code structure and calculation reuse, rather than trade signals or strategy performance.

Key ideas

  • A custom function can make indicator calculations reusable across Expert Advisors.
  • The function can accept indicator inputs and return calculated series through reference arrays.
  • A success flag can indicate whether enough historical bars exist for calculation.
  • Skipping calculations on the unfinished bar can reduce unnecessary recalculation.
  • The article validates one RAVI implementation by comparing its outputs with the custom indicator in a tester.

Tags

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