Skip to content
All library documents

Implementing a Non-Repainting Recursive SuperTrend Indicator in MQL5

Article MQL5 articles

Summary

This tutorial explains SuperTrend as a volatility-scaled band system with three linked parts: ATR offsets around the high-low midpoint, bands that ratchet in the favorable direction, and a trend state that changes when price closes through the opposite band. The focus is implementing that recursive calculation correctly in MQL5. Because each bar depends on stored values from the prior bar, the article emphasizes consistent series indexing, calculation order, and preserving state across updates.

The implementation stores recursive bands and trend direction in terminal-managed calculation buffers, creates the ATR handle during initialization, and recalculates recent bars during live operation. It also describes plotting separate uptrend and downtrend lines and placing arrows only after a confirmed trend flip, reducing transient signals on the forming bar. The discussion distinguishes normal changes to an open candle from closed-bar changes caused by state bugs or legitimate history reloads. It presents engineering guidance, not evidence of strategy returns; SuperTrend settings and signal quality remain market-dependent.

Key ideas

  • SuperTrend combines ATR-based bands, a one-way ratchet, and a trend state triggered by closes across the opposite band.
  • Recursive band values require correct indexing and access to the prior bar’s stored state.
  • Terminal-managed calculation buffers can preserve recursive history as new bars arrive.
  • The indicator should distinguish recalculation of live bars from unintended changes to closed-bar values.
  • Arrows can be limited to confirmed trend reversals, but the tutorial does not establish trading profitability.

Tags

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