Skip to content
All library documents

Using Sparse Tables and Cleaned Data to Speed Up MQL5 Trailing Stops

Article MQL5 articles

Summary

The article addresses repeated historical high and low scans in custom trailing-stop logic. It describes a sparse table that precomputes range minima or maxima over power-of-two intervals, trading memory and setup work for constant-time range queries. The method is most useful when an expert advisor makes many queries over large lookback windows; for occasional queries, preprocessing may not be worthwhile. An ATR-based excursion check is also described as a way to screen noisy stop adjustments.

A second part proposes preparing market data outside the terminal with Polars and storing cleaned, timestamped rates in SQLite for the EA to retrieve. The article discusses timing comparisons and matching behavior between tester and live data, but the supplied text gives no concrete measured values or detailed validation results. Thus, the performance and reproducibility benefits are engineering goals that depend on the implementation and data pipeline, rather than demonstrated trading returns.

Key ideas

  • A sparse table stores precomputed extrema for power-of-two intervals and answers range queries in constant time.
  • Building the table takes additional preprocessing and memory, so its advantage depends on query frequency and window size.
  • The proposed trailing logic uses minimum prices for long positions and maximum prices for short positions.
  • An ATR-based excursion validator can filter potential stop changes caused by small price moves.
  • A Polars-to-SQLite pipeline is proposed to supply cleaned, timestamped rates to the expert advisor.

Tags

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