SuperTrend Indicator — Detailed Description

A complete SuperTrend indicator implementation for MetaTrader 5, built from first principles rather than adapted from an existing template. The indicator combines three core ideas: a volatility-scaled envelope derived from ATR (Average True Range), a ratchet mechanism that only ever tightens the band in the trend's favor rather than jumping around with every new bar, and a binary trend flag that flips only when price genuinely closes through the band on the opposite side.

What sets this implementation apart is how its internal recursive state is handled. Rather than storing the band's memory in plain, manually-managed arrays — a common source of subtle bugs where state can silently reset or lose continuity across bars — the internal upper-band, lower-band, and trend-flag values are registered as proper indicator calculation buffers (INDICATOR_CALCULATIONS). This hands their sizing and bar-to-bar persistence over to the terminal itself, eliminating an entire category of bug that can otherwise cause a SuperTrend line to behave erratically, particularly during backtesting.

The indicator uses consistent series indexing throughout, with a deliberate seeding process on first load that establishes the recursive state from the oldest usable bar in the available history, rather than assuming zero or default values. Buy and sell arrows are only plotted after a trend reversal is confirmed on a bar that is no longer at risk of being reprocessed — a small but important detail that prevents an arrow from appearing and then vanishing on the next tick, which is a common visual bug in less careful implementations.

This indicator was built, reviewed, and refined through multiple rounds of technical review as part of the "Making Custom Indicators for Beginners" article series, where every design decision — including a real, documented bug in an earlier version and its fix — is explained in full. It is provided here as a clean, standalone, non-repainting SuperTrend implementation suitable for direct use or as a reference for anyone building their own custom trend indicators in MQL5.