Overview
Supertrend trend line built from ATR, coloured by direction, with optional flip arrows and a one-per-bar alert when a closed bar flips the trend.
Supertrend is a trailing trend line built from the Average True Range (ATR). It sits below price while the trend is up and above price while it is down, so the current direction and a volatility-based trailing level are visible at a glance. This version draws the up and down sections in two colours, can mark every flip with an arrow, and can alert you once when a closed bar flips the trend.
How it works
- ATR uses Wilder smoothing. The first value is the simple average of the first N true ranges; after that
ATR = (previous ATR x (N - 1) + true range) / N. - Basic bands:
middle = (high + low) / 2,upper = middle + multiplier x ATR,lower = middle - multiplier x ATR. - Final bands only tighten. The final lower band may rise freely, but it can only fall when the previous close was below it. The final upper band works the same way in reverse.
- Trend: an up trend turns down when the close falls below the final lower band; a down trend turns up when the close rises above the final upper band. While the trend is up the line shows the final lower band, while it is down the line shows the final upper band.
- Arrows are placed under the low of an up-flip bar and above the high of a down-flip bar.
- Alert: when the last closed bar flipped the trend, one alert is shown for that bar.
The indicator only recalculates the newest bar on each tick, so it stays light even on long histories.
Inputs
| Input | Default | What it does |
|---|---|---|
| ATR period | 10 | Number of bars in the Wilder ATR. |
| ATR multiplier | 3.0 | Distance of the line from the bar middle, in ATRs. |
| Up-trend colour | Medium sea green | Colour of the line and arrows in an up trend. |
| Down-trend colour | Crimson | Colour of the line and arrows in a down trend. |
| Line width | 2 | Thickness of the Supertrend line (1-5). |
| Show arrows | true | Draws an arrow on each bar where the trend flips. |
| Alert on flip | false | Shows one alert when a closed bar flips the trend. |
How to use it
- In MetaTrader choose File > Open Data Folder.
- MT4: copy
FXN_Supertrend.mq4intoMQL4/Indicators. MT5: copyFXN_Supertrend.mq5intoMQL5/Indicators. - Restart the terminal, or right-click Indicators in the Navigator and choose Refresh. If the indicator does not appear, open the file in MetaEditor and press F7 to compile it.
- Drag the indicator onto a chart, adjust the inputs and press OK.
Start with the defaults (10, 3.0) on H1 or H4. A smaller multiplier such as 2.0 follows price more closely and flips more often; a larger one such as 4.0 gives fewer, slower flips. Many traders use the line as a trend filter (only look for buys while it is green) or as a reference for a trailing stop.
Good to know
- Forming bar: the value on the current, unfinished bar moves with price, and a flip (and its arrow) can appear and disappear until that bar closes. Values on closed bars do not change. The alert only uses closed bars.
- In sideways markets Supertrend flips often and gives late, losing signals; it works best when price is trending.
- The ATR is calculated inside the indicator with Wilder smoothing, so values can differ slightly from versions that use a simple-average ATR.
- Works on any symbol and timeframe. It does not open, close or modify trades.
- The two colours are separate buffers (up and down), which makes them easy to read from an Expert Advisor with
iCustom: buffer 0 is the up line, buffer 1 the down line, empty values mean the other side is active.
Trading carries risk. Test on a demo account first; past results do not predict future results.
At a glance
- What it is
- A free Indicator for MetaTrader 5, written in MQL5.
- What it does
- Supertrend trend line built from ATR, coloured by direction, with optional flip arrows and a one-per-bar alert when a closed bar flips the trend.
- Shared by
- Alex
- Licence
- MIT
- Version
- 1.0 (1 Dec 2026)
- Settings
- 7 inputs
- Lab check
- Compiled with MetaEditor build 6333 for MT5 on 1 Dec 2026: 0 errors, 0 warnings.
- Price
- Free to download
Settings read from the code
| Input | Type | Default | Note |
|---|---|---|---|
| InpAtrPeriod | int | 10 | ATR period (Wilder smoothing) |
| InpMultiplier | double | 3.0 | ATR multiplier for the band distance |
| InpUpColor | color | clrMediumSeaGreen | Colour of the up-trend line |
| InpDownColor | color | clrCrimson | Colour of the down-trend line |
| InpLineWidth | int | 2 | Line width (1-5) |
| InpShowArrows | bool | true | Draw an arrow on the bar where the trend flips |
| InpAlertOnFlip | bool | false | Alert once when a closed bar flips the trend |
How to use it
- Download the compiled file (or the source and compile it in MetaEditor).
- Put it in MetaTrader: File → Open Data Folder → MQL5 → Indicators, then refresh the Navigator.
- Test it on a demo account before any real money.
- Want changes? Open a copy in your Lab and ask for them in plain words.