Skip to content
All library documents

Using MQL5 Decorators to Add Indicator Logging, Timing, and Filters

Article MQL5 articles

Summary

This article demonstrates the decorator pattern for adding logging, execution timing, and threshold filtering around MQL5 indicators without changing their calculation classes. A shared interface gives raw indicators and wrappers the same GetValue and GetName methods. Each decorator delegates to the object it wraps, so callers can use a single interface whether they hold a plain indicator or a chain of wrappers.

The examples include RSI and moving-average components, plus decorators that log values, measure elapsed microseconds, or return zero outside a configured range. The article describes dynamic ownership: each wrapper deletes its wrapped object, allowing the caller to clean up a whole chain by deleting its outermost object. It provides example code and an EA demonstration, but no performance benchmarks or evidence that the pattern improves trading results. Filtering also changes the values delivered to the caller, so its effect depends on the use case and chosen thresholds.

Key ideas

  • A shared indicator interface lets raw computations and wrappers remain interchangeable to callers.
  • Decorators add logging, timing, or filtering by delegating indicator requests through a chain.
  • A base decorator can centralize delegation and ownership of the wrapped indicator.
  • Deleting the outermost dynamically allocated decorator can release the full chain when ownership is consistent.
  • Threshold filtering changes the value received by downstream code and should match the intended application.

Tags

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