Supertrend Trend Fill with Change Alerts
- Indicators
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.2
Supertrend Trend Fill with Change Alerts is a TV-compatible Supertrend for MetaTrader 5. It uses the same calculation as the "Supertrend" indicator built into TradingView and draws it the same way: a green line below price in an up trend, a red line above price in a down trend, and a light fill between the line and the middle of each candle body.
Supertrend shows the direction of the trend. It is a charting aid, not a buy or sell signal, and it does not predict where price will go.
HOW IT IS CALCULATED
- ATR Length 10, Factor 3.0, source hl2 = (high + low) / 2, ATR smoothed with RMA (Wilder) - the TradingView defaults.
- Upper band = source + Factor x ATR, lower band = source - Factor x ATR. Each band only moves in the direction of the trend, as in TradingView's ta.supertrend().
- The trend turns up when the close goes above the upper band, and turns down when the close goes below the lower band.
- Options that TradingView's built-in version does not have: ATR by SMA instead of RMA, and close / hlc3 / ohlc4 as the source. With these options the values no longer match TradingView.
HOW WE CHECKED IT
- On TradingView's own prices (EURUSD 1h), our formula gave the same trend direction as TradingView's built-in Supertrend on 280 of 280 bars.
- On a broker's MT5 chart the numbers differ a little, because the prices come from a different data feed. In our EURUSD H1 test, 199 of 200 compared bars had the same direction and the line differed by 1.3 pips on average. Near a trend change, a small price difference can move the change by one bar.
DISPLAY
- Green up line (#4CAF50) and red down line (#FF5252), width 1 to 5.
- Background fill between the line and the candle body middle (open + close) / 2, opacity 1 to 100 % mixed with the chart background. It can be switched off.
- One small difference: TradingView leaves the fill empty on the bar where the trend changes; here a small piece of fill is drawn there.
- Optional markers on the bars where the trend changes (off by default).
THE LATEST BAR (REPAINT)
- The bar that is still forming is recalculated on every tick, exactly like TradingView. Its line and direction can change until the bar closes.
- Once a bar has closed, its values never change.
ALERTS (OFF BY DEFAULT)
- One condition: the trend direction changed on the bar that has just closed. Checked once per bar.
- Bars that closed before the indicator was loaded do not raise alerts, so attaching it or restarting MT5 does not produce old alerts.
- Message example: "Supertrend TV EURUSD H1: trend changed to UP (1.08123)".
- Pop-up, sound and push notification can be combined. Push needs your MetaQuotes ID in the terminal options. Alert texts in English or Japanese.
FOR EA AND iCUSTOM USERS
- Buffer 0 = Supertrend value, buffer 1 = direction: +1 = up trend, -1 = down trend.
- Note: the sign is the opposite of the "direction" variable in TradingView's Pine Script (there -1 means up).
- Bars without a value return EMPTY_VALUE. Both values also appear in the Data Window.
- When an EA or another indicator loads it through iCustom, or when it is added to a chart with ChartIndicatorAdd, it draws nothing on the chart and raises no alerts; it only calculates the buffers.
PLEASE READ BEFORE USE
- "Chart on foreground": so that the candles stay visible above the fill, the indicator turns on this chart setting (input "Draw price bars above the fill"). When you remove the last copy, the original setting is restored. If another tool by the same author that uses this setting is still on the chart, the setting is restored only when the last of them is removed.
- For the first few seconds after loading (up to about 15 seconds), the short name in the indicator list may briefly show "probe#..." while the indicator checks whether it is on a chart. This is normal.
- ATR (RMA) depends very slightly on how much history is loaded; in our test the difference was below 0.0000001.
- In the Strategy Tester it raises no alerts.
- No DLLs, no external files, no internet connection.
- It does not trade, and no trading result is promised.
INPUTS
Supertrend: ATR Length (10, 1-1000), Factor (3.0, 0.01-100), ATR calculation method (RMA), Source of the bands (hl2)
Style: Up Trend line color (#4CAF50), Down Trend line color (#FF5252), Line width (2, 1-5), Show background fill (true), Fill opacity % (10, 1-100), Draw price bars above the fill (true), Show trend-change markers (false), Marker size (1, 1-5)
Alerts: Alert: trend direction changed (false), Alert by pop-up (true), Alert by sound (false), Alert by push notification (false), Language (Auto = terminal language, English or Japanese)
If an input is out of range, the indicator does not load and writes the reason to the Experts log.
SUPPORT
Questions about installation, settings and bugs are welcome through MQL5 messages. Questions about market direction or individual trades are outside the support scope.
This is part of a series of free TV-style tools. An MT4 edition is also available as a separate product. Other tools by the same author are listed on my seller profile.
TradingView is a trademark of TradingView, Inc. This product is not affiliated with, sponsored by or endorsed by TradingView, Inc.
