SuperTrend EA MT5 — No Code

SuperTrend EA for MT5: classic ATR 10 / multiplier 3 settings, how to build it in the Strategy Builder (Step 3 entry rules), and the band logic in MQL5.

📖 6 min read

📝 1,141 words

🏷️ MQL5 and Expert Advisors

Share this article:

SuperTrend EA for MT5 — No Code

Can I build a SuperTrend EA for MT5 without coding?

Yes. SuperTrend is one of the 47 indicator types in the MT5 Strategy Builder. Add it in Step 3 (Entry rules): Buy when SuperTrend(10, 3) turns up (or Close crosses above the SuperTrend line), and the Sell rule turned around, then exits and risk, then press Get the code in Step 7. If you prefer to hand-code it, compute the bands from ATR in your EA, or read a SuperTrend indicator from the MQL5 Code Base (outline below).

Disclosure: This is an educational guide, not financial advice. Backtest and Demo results do not guarantee live profits.

Related guides: SuperTrend Indicator (academy) · Build EA Without Coding · MA Crossover EA — No Code · Backtest in Strategy Tester · EA Strategy Library


What Is a SuperTrend EA?

A SuperTrend Expert Advisor automates a well-known trend-following rule:

SignalRule (typical)
Buy (long)Price flips above the Supertrend line — SuperTrend turns up / is in an uptrend
Sell (short)Price flips below the line — downtrend

Supertrend uses ATR to place a dynamic band; the line switches between upper and lower bands when price closes through the band. In MQL5, an EA's logic runs inside OnTick() [1]; MetaTrader 5 has no built-in SuperTrend function, so the EA computes the bands from ATR itself or reads a custom indicator.

Why traders search for this: Clear trend signals without coding ATR math. Most tutorials show Pine or MQL5 code. This guide explains the rule, what it takes in MQL5, and the closest no-code path in AlfaTactix today.


Classic Settings and When It Works

SettingStarter valueNotes
ATR length10Builder default (1 … 100)
Factor3Builder default (0.1 … 20); higher = wider band, fewer flips
Band centreMedian (High + Low) / 2Classic formula; some versions use Close
TimeframeM15 or H1M5 = more signals; H4 = slower
SymbolEURUSD, GBPUSDLower spread helps trend systems
Time window1–2 closed barsHas been true for N bars in a row on “is in an uptrend” reduces one-bar noise after a flip

Works best: Clear trends, liquid sessions (London / New York overlap).

Struggles in: Tight ranges — repeated flips (whipsaw). Mitigate with a Market sessions or Spread limit filter and a stop loss.

For indicator theory and limitations, see SuperTrend Indicator — Settings & Entries.


SuperTrend Logic in MQL5

Without a built-in function, a hand-written EA follows these steps on each new closed bar:

  1. Create one ATR handle with iATR [2] in OnInit and read the last closed value with CopyBuffer [3].
  2. Compute the basic bands: mid = (High + Low) / 2; upper = mid + Multiplier × ATR; lower = mid − Multiplier × ATR.
  3. Ratchet them: in an uptrend the lower band may only rise; in a downtrend the upper band may only fall.
  4. Flip the direction up when Close breaks above the previous upper band, and down when Close breaks below the previous lower band. A flip is your entry signal.
// OnInit
atrHandle = iATR(_Symbol, PERIOD_M15, 10);

// OnTick, once per new bar
CopyBuffer(atrHandle, 0, 1, 1, atr);      // ATR of the last closed bar
double mid   = (high[1] + low[1]) / 2.0;
double upper = mid + 3.0 * atr[0];
double lower = mid - 3.0 * atr[0];
// ratchet the bands, then compare close[1] with the previous bands to detect a flip

Alternative: download a SuperTrend indicator from the MQL5 Code Base [4] and read it with iCustom(). Check which buffer holds the line and which holds the direction before you trade on it.


SuperTrend in the Builder

If you want an Expert Advisor without writing MQL5, add the SuperTrend indicator in Step 3. Its parameters are the ATR length (default 10) and the factor (default 3). It has a line and a direction.

StepSetting
Step 3 — Entry rulesPrice crossing above the SuperTrend line for Buy, below it for Sell
Step 4 — FiltersOptional session (London / New York) and spread filter
Steps 5 and 6 — Exits and riskATR-based stop loss, fixed lot or risk %

For a different trend rule to compare, see MA Crossover EA — No Code. Compare both in the Strategy Tester before choosing.


Trader-Reported Themes (Forums)

Educational summary — not quotes from individuals.

In public threads on r/algotrading and r/Forex, traders often report similar themes about trend-following tools such as Supertrend:

  • Whipsaw in ranges — multiple small losses when price chops around the line
  • Session matters — filtering to London / New York overlap is a common mitigation
  • Backtest vs live — spread and slippage change results; validate on Demo (Backtest an EA in the MT5 Strategy Tester)
  • Not a holy grail — combination with risk limits and filters beats “set and forget”

We do not attribute profitability to any influencer “secret” strategy. Validate on your broker and symbol.


Compile and Backtest

  1. Put your .mq5 in MQL5/Experts (hand-written, or from Get the code in Step 7) and compile (F7) in MetaEditor [5].
  2. Strategy Tester: Every tick, realistic spread, 6–12 months.
  3. Demo before live.

Error 10016: Invalid Stops.


Improvements: Filters and Risk

ProblemLever
Whipsaw in rangeWait 2–3 closed bars after a flip; trade only London / New York; higher Factor
Late entriesLower Factor or shorter ATR length (more noise)
Spread costSkip entries when the spread is above your limit
Stop placementATR-based stop sized to the same ATR the bands use

Next Steps

References: Investopedia — SuperTrend [6] · TradingView SuperTrend [7] · MetaTrader 5 Strategy Tester [8].

Frequently Asked Questions

Yes. SuperTrend is one of the 47 indicator types in the MT5 Strategy Builder. Add it in Step 3 (Entry rules) and write a rule such as Buy when SuperTrend turns up, or Close crosses above the SuperTrend line (the Sell rule turned around). Then set exits and risk and press Get the code in Step 7. You can also code it in MQL5 (bands from iATR, or a Code Base indicator read with iCustom).

Common starters: ATR length 10, Factor 3 on M15 or H1 for forex majors. A higher Factor (3.5–4) means fewer flips; a lower ATR length reacts faster. Always backtest on your symbol and broker spread.

No. MT5 has no built-in SuperTrend function. An EA either computes the bands from an iATR handle or reads a custom SuperTrend indicator from the MQL5 Code Base with iCustom.

No. SuperTrend is a trend-following rule set. It often whipsaws in sideways markets. This guide is educational: backtest, then Demo, then live only with risk you can afford.

See the AlfaTactix SuperTrend indicator guide at /academy/indicators/supertrend for ATR-based bands and signal intuition, then return here for the MQL5 outline.

The form has 47 indicator types, among them RSI, SMA, EMA, WMA, MACD, Stochastic, Williams %R, CCI, Momentum, Bollinger Bands, ATR, Volume, OBV, SuperTrend and ADX. In Step 7 you press Get the code and compile the .mq5 once (F7) in MetaEditor.

References

  1. MetaQuotes, MQL5 Reference. OnTick. https://www.mql5.com/en/docs/event_handlers/ontick
  2. MetaQuotes, MQL5 Reference. iATR. https://www.mql5.com/en/docs/indicators/iatr
  3. MetaQuotes, MQL5 Reference. CopyBuffer. https://www.mql5.com/en/docs/series/copybuffer
  4. MQL5.community. MQL4 and MQL5 Source Code Library. https://www.mql5.com/en/code
  5. MetaQuotes, MetaEditor Help. Welcome to algorithmic trading!. https://www.metatrader5.com/en/metaeditor/help
  6. Investopedia. Mastering Trend Analysis with the Supertrend Indicator. https://www.investopedia.com/supertrend-indicator-7976167
  7. TradingView. Supertrend. https://www.tradingview.com/support/solutions/43000634738-supertrend/
  8. MetaQuotes. MetaTrader 5 Built-in Trading Strategy Tester. https://www.metatrader5.com/en/automated-trading/strategy-tester