Skip to content
All library documents

A Non-Repainting SuperTrend Using ATR Bands and Persistent State

Article MQL5 code base

Summary

This document explains a MetaTrader 5 SuperTrend indicator built from an Average True Range based envelope, bands that ratchet in the direction of an established trend, and a binary trend state. The trend changes only when price closes beyond the band on the opposite side. The description focuses on implementation choices that preserve the indicator's recursive state across bars, including using calculation buffers for the internal bands and trend flag, and seeding that state from available historical bars.

Reversal arrows are plotted only after confirmation on a bar considered safe from reprocessing, a design intended to avoid transient signals. The author presents the result as non-repainting and as a reference implementation, with its development discussed alongside a prior bug and its correction. The document offers no backtest, trading performance, or evidence that SuperTrend signals are profitable. Its main value is explaining indicator construction and state management, not validating a strategy.

Key ideas

  • The SuperTrend envelope scales with volatility using Average True Range.
  • Its bands ratchet with the trend, and the trend state flips after a close through the opposite band.
  • Calculation buffers preserve recursive band and trend values across bars.
  • Seeding state from historical data helps maintain continuity when the indicator first loads.
  • Reversal arrows are delayed until confirmation to avoid transient signals, but no trading results are provided.

Tags

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