Matching TradingView SuperTrend in an MQL5 Port
Summary
This document explains how to reproduce TradingView’s SuperTrend indicator in MQL5 and verify that the port matches bar by bar. It highlights three sources of divergence: using EMA smoothing instead of Wilder’s RMA for ATR, adopting a different true-range warm-up convention, and failing to preserve the indicator’s trailing band rules. It also notes that TradingView’s direction values may seem inverted relative to common expectations, so changing their sign can reverse downstream signals.
The author describes exporting OHLC data and indicator outputs, then comparing them with a Python reference computed from the same rows. Reported comparisons across five instruments show no direction mismatches and only negligible line differences; deliberate errors are also used to check that the verifier can reject a bad port. These results support implementation fidelity for the tested symbols and timeframes, not profitability. The described scope is limited to the standard SuperTrend on hl2, a single symbol and timeframe, and closed bars; a forming bar is excluded because its value changes.
Key ideas
- SuperTrend ATR uses Wilder smoothing with a specific initialization, which differs from a conventional EMA.
- True-range warm-up conventions can cause persistent differences in a recursive ATR calculation.
- The trailing bands tighten and yield only after price closes through them, affecting trend changes.
- A shared-input, bar-by-bar comparison against a reference can expose implementation discrepancies.
- The reported checks establish indicator agreement on selected data, not trading performance.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.