Supertrend Indicator: Settings, Strengths and When It Fails
How the Supertrend indicator is calculated, what the ATR length and multiplier change, where it works and where it whipsaws, with Pine Script v6 code.
Supertrend Indicator: Settings, Strengths and When It Fails
TLDR
The Supertrend indicator is an ATR-based trailing line that sits below price in an uptrend and above price in a downtrend, and flips sides when the close crosses it. Its two inputs are the ATR length (commonly 10) and the ATR multiplier (commonly 3), and together they set how far the line trails and therefore how often it flips. It is a clean trend filter and a reasonable trailing stop, but it is not a prediction tool: in a sideways market it flips repeatedly, and after a sharp reversal it reacts late by design. This article shows the arithmetic, a settings comparison, an original Pine Script v6 implementation with a confirmation filter, and the specific conditions under which Supertrend loses money so you can test for them.
How Supertrend is calculated
Supertrend is often described as "ATR bands with memory". Each bar, two basic bands are computed around the bar's midpoint:
- Upper basic band = (high + low) / 2 + multiplier x ATR
- Lower basic band = (high + low) / 2 - multiplier x ATR
The memory comes from a ratchet rule. In an uptrend the indicator plots the lower band, and that band is only allowed to rise: if today's lower basic band is below yesterday's final lower band, yesterday's value is kept. In a downtrend the indicator plots the upper band, which is only allowed to fall. The ratchet is released when price closes through the band, which is also the moment the trend flips. The band on the other side then starts fresh from its basic value.
Two consequences follow from this construction. First, Supertrend is a trailing stop with a direction label attached, not an oscillator or a moving average; it tells you which side of a volatility-scaled stop price is on. Second, because the only thing that moves the line toward price is a new bar with a tighter basic band, the line can sit flat for many bars while price drifts sideways, and then a single wide bar flips it.
The indicator is commonly attributed to the French trader Olivier Seban. The sign convention for the direction output differs between implementations, which matters if you reuse someone else's code: TradingView's built-in ta.supertrend() returns a direction value that is negative in an uptrend, while many standalone scripts use positive one for up. The code later in this article uses its own explicit state variable so the meaning is unambiguous.
What the two settings actually change
Both inputs scale the same quantity, the distance between price and the line, so they interact. A shorter ATR length makes the band react faster to a change in volatility; a smaller multiplier keeps the band closer to price regardless of volatility. In practice traders adjust the multiplier more than the length, because the multiplier has a direct, linear effect on flip frequency.
| Setting pair | Line behavior | Flip frequency | Typical use | Main cost |
|---|---|---|---|---|
| 7 / 2.0 | Hugs price; reacts within a few bars | High | Scalping exits, tight trailing stops on intraday charts | Many false flips in consolidation |
| 10 / 3.0 | Moderate distance; the common default | Medium | General trend filter on 15 minute to daily charts | Gives back a meaningful share of a move before exiting |
| 14 / 4.0 | Far from price; flips only on decisive moves | Low | Position trading, regime filter for other systems | Late entries, large open-profit giveback |
| 20 / 5.0 | Very wide; months between flips on daily charts | Very low | Long-term bias only | Mostly useless for entries |
None of these pairs is correct in general. The right question is not "which settings are right" but "which settings produce a flip frequency that matches the holding period I want, on the instrument and timeframe I trade, after costs". That is a backtest question, and the parameter surface should be smooth: if 10 / 3.0 is profitable and 10 / 2.8 and 10 / 3.2 are both losers, you have found noise, not an edge. The backtesting platforms comparison covers how to run that kind of sensitivity test honestly.
Worked example: the ratchet in numbers
Suppose a stock index future is in an uptrend according to Supertrend with settings 10 / 3.0, and on bar one the 10-period ATR is 12.0 points. The bar's high is 5,010 and its low is 4,990, so the midpoint is 5,000.
- Lower basic band = 5,000 - 3.0 x 12.0 = 4,964.0
- Upper basic band = 5,000 + 3.0 x 12.0 = 5,036.0
Because the trend is up, the indicator plots 4,964.0. Suppose the previous bar's final lower band was 4,958.5. The new basic value is higher, so the ratchet accepts it: the line moves up to 4,964.0.
On bar two the market pulls back. High 5,004, low 4,980, midpoint 4,992, and ATR has risen slightly to 12.6. Lower basic band = 4,992 - 3.0 x 12.6 = 4,954.2. That is below the previous final value of 4,964.0, so the ratchet rejects it and the line stays at 4,964.0. The close is 4,985, which is above the line, so the trend stays up.
On bar three the pullback deepens and the bar closes at 4,961. The close is below 4,964.0, so the trend flips to down. The indicator now plots the upper band, starting fresh from the bar's upper basic value. If that bar's midpoint was 4,975 and ATR 13.0, the new line is 4,975 + 39.0 = 5,014.0. A trader who used the line as a stop exited at roughly 4,961 minus slippage, having entered at some earlier flip. Notice that the exit happened 3.0 ATR below the recent midpoint by construction: Supertrend always gives back about that much of a move before it exits. That giveback is the price of staying in trends longer, and it is the number to compare against your average winner when you choose a multiplier.
Where Supertrend earns its place
- As a regime filter. Taking a breakout or pullback system's long signals only when Supertrend is up, and shorts only when it is down, is a simple way to stop fighting the dominant move. Because the filter is a single state, it is easy to combine with other factors without double counting; see the independence discussion in the confluence article.
- As a trailing stop. The ratchet behavior is exactly what a trailing stop should do: never loosen, tighten only when volatility and price allow. Using the line as a stop rather than a fixed-point trail adapts the distance to current volatility automatically.
- As a readable chart overlay. It is a single colored line. Discretionary traders use it to avoid counter-trend trades without needing to interpret anything.
- In automated systems. The logic is fully specified, uses only completed bars if you require confirmation, and is cheap to compute. It ports cleanly from Pine Script to MQL5, which is one reason it is a frequent component in the expert advisors we build.
When Supertrend fails
Sideways markets
This is the central weakness and it cannot be tuned away. In a range, price repeatedly closes through the line in both directions. Each flip is a losing exit and a late entry in the new direction, and the losses are each roughly the band width. Widening the multiplier reduces the count of flips but increases the size of each loss, so the total drawdown in a range does not fall as much as the flip count suggests. The honest fix is an external condition that detects the range and stands aside: an ADX threshold, a minimum band-width expansion, or a time-of-day filter. The Pine code below includes an ADX gate for that reason.
Sharp reversals
After a strong trend the line is 3 ATR away from the recent midpoint. A fast reversal, especially a gap, moves price through the line in one or two bars, and the exit fills well below where the line was. Supertrend does not reduce this risk; a hard stop or a time stop does.
Low volatility compression before a breakout
ATR falls during compression, so the band tightens to within a few points of price just before the move. The first expansion bar can flip the indicator against the eventual direction, after which the real move flips it back. Two losses in a row at the exact moment a breakout trader wants to be positioned. This is the scenario where a squeeze detector such as the one in our TTM Squeeze explainer is more useful than Supertrend.
Intrabar flicker
On the live bar the close changes with every tick, so the trend can flip and unflip before the bar closes. A script that fires an alert on the first flip will fire on signals that disappear. Requiring barstate.isconfirmed removes the flicker at the cost of acting one bar later. The non-repainting indicators article covers why this matters and how to test for it.
Parameter sensitivity on a short history
Because flips are discrete events, a small change in the multiplier can move one flip across a large bar and change the backtest noticeably. On a few hundred bars this looks like a sharp optimum. On several years of data the optimum flattens out. Treat any sharp peak in a Supertrend parameter scan as a warning sign.
Original Pine Script v6: Supertrend with a confirmation and ADX gate
The script below implements Supertrend from scratch rather than calling the built-in, so the direction logic is visible, and adds two gates: signals fire only on confirmed bars, and only when ADX is above a threshold so that flips inside a flat range are suppressed. It is kept short on purpose.
//@version=6 indicator("Supertrend with ADX gate", overlay = true)atrLen = input.int(10, "ATR length", minval = 1) mult = input.float(3.0, "ATR multiplier", step = 0.1, minval = 0.1) adxLen = input.int(14, "ADX length", minval = 1) adxMin = input.float(20.0, "Minimum ADX to signal", step = 1.0)
atr = ta.atr(atrLen) mid = (high + low) / 2 upBasic = mid + mult * atr dnBasic = mid - mult * atr
var float upBand = na var float dnBand = na upBand := na(upBand[1]) ? upBasic : (upBasic < upBand[1] or close[1] > upBand[1]) ? upBasic : upBand[1] dnBand := na(dnBand[1]) ? dnBasic : (dnBasic > dnBand[1] or close[1] < dnBand[1]) ? dnBasic : dnBand[1]
var int dir = 1 if dir == -1 and close > upBand dir := 1 else if dir == 1 and close < dnBand dir := -1
stLine = dir == 1 ? dnBand : upBand [diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)
flipUp = dir == 1 and dir[1] == -1 and barstate.isconfirmed flipDown = dir == -1 and dir[1] == 1 and barstate.isconfirmed longOk = flipUp and adx > adxMin shortOk = flipDown and adx > adxMin
plot(stLine, "Supertrend", color = dir == 1 ? color.green : color.red, linewidth = 2) plotshape(longOk, "Long flip", shape.triangleup, location.belowbar, color.green, size = size.small) plotshape(shortOk, "Short flip", shape.triangledown, location.abovebar, color.red, size = size.small) alertcondition(longOk, "Supertrend long", "Supertrend flipped up, ADX above threshold") alertcondition(shortOk, "Supertrend short", "Supertrend flipped down, ADX above threshold")
Design notes:
- The band ratchet is written out explicitly. The
close[1] > upBand[1]term is what releases the ratchet after a flip, so the new band starts from its basic value instead of inheriting a stale level from the other regime. diris avarinteger, so it carries its value from bar to bar without the sign ambiguity of the built-in.- The ADX gate suppresses signals, not the line itself. You still see every flip; you only get alerted on the ones that occur while the market is trending by ADX's measure. The threshold of 20 is a starting point to test, not a recommendation.
- To turn this into a strategy, replace the plotshapes with
strategy.entrycalls and usestLineas the stop instrategy.exit. The line is already a trailing stop, so no extra trailing logic is needed.
Combining Supertrend with other tools
Supertrend works better as one component than as a complete system. Three combinations that are common and testable:
- Supertrend direction plus pullback entry. Only trade in the Supertrend direction, but enter on a pullback to a short moving average or a prior level rather than on the flip itself. This reduces the "enter 3 ATR late" problem while keeping the regime filter.
- Two Supertrends. A slow pair (for example 14 / 4.0) for direction and a fast pair (7 / 2.0) for the trailing stop. The slow one decides whether to be in; the fast one decides when to get out. This is a standard way to shorten the giveback without increasing false entries.
- Supertrend plus a breakout trigger. Take an opening range breakout, as described in the ORB strategy article, only in the direction of a higher-timeframe Supertrend. The higher-timeframe value must be fetched with a confirmed offset or it will repaint.
In each case the Supertrend contributes a direction and a stop. Do not add a second trend indicator on the same timeframe alongside it; a 50-period EMA slope and a 10 / 3.0 Supertrend agree almost all the time and the second one adds nothing except false confidence.
FAQ
Which Supertrend settings should I use?
There is no universal answer, and anyone who gives you one without naming an instrument, a timeframe and a test period is guessing. The default of 10 / 3.0 is a reasonable starting point for 15 minute to daily charts. Scan the multiplier between roughly 2 and 4 and the length between 7 and 20 on your own data, with costs included, and prefer a region where neighboring settings behave similarly over a single sharp peak.
Does the Supertrend indicator repaint?
Not in the sense of rewriting history, provided it is computed from the chart's own bars. The line and the flips on closed bars never change. On the live bar the flip can appear and disappear as the close moves, which is intrabar flicker rather than repainting; requiring a confirmed bar removes it. If you pull Supertrend from a higher timeframe with request.security without an offset, that version does repaint.
Is Supertrend a leading or lagging indicator?
Lagging. It cannot flip until price has already moved roughly multiplier x ATR against the prior trend. It is designed to stay in trends, not to call turns.
Can I use Supertrend on a 1 minute chart?
You can, and the arithmetic is the same, but 1 minute bars spend a large share of the day in ranges where Supertrend flips repeatedly. On that timeframe a regime filter is close to mandatory and the spread becomes a meaningful fraction of each flip's cost. Most traders who use it intraday work on 5 or 15 minute charts.
Supertrend or a moving average crossover?
They answer similar questions with different behavior. A crossover's lag depends on the two lengths; Supertrend's lag depends on volatility, so it adapts when the market gets quieter or louder. Supertrend also gives you a stop level directly, which a crossover does not. In a very smooth trend the crossover often holds on longer; in a choppy trend Supertrend's volatility scaling tends to produce fewer false exits. Test both on your instrument rather than assuming.
Where Viprasol fits
Viprasol builds custom indicators and automated systems for TradingView and MetaTrader. If you want Supertrend as part of a larger tool, with multi-timeframe direction, an ADX or session gate, a position-size panel, or alerts formatted for a webhook, our Pine Script development service delivers it as readable v6 code that you own. The same logic ported to MQL5 for an expert advisor, with the ratchet implemented on completed bars only, is covered by our MT5 indicator development and EA services. Pricing is on the pricing page; describe the rule set you want through the contact form.
Risk disclaimer: trading futures, forex, CFDs and crypto involves substantial risk of loss. This article is educational and is not investment advice; the settings and examples shown are illustrative and do not indicate future performance.
External Resources
About the Author
Viprasol Tech Team
Custom Software Development Specialists
The Viprasol Tech team specialises in algorithmic trading software, AI agent systems, and SaaS development. With 1000+ projects delivered across MT4/MT5 EAs, fintech platforms, and production AI systems, the team brings deep technical experience to every engagement.
Ready to Automate Your Trading?
Discuss a custom Expert Advisor with defined strategy rules, risk controls and a testing plan.
Free consultation • No commitment • Response within 24 hours
Need a custom EA or trading bot built?
We build MT4/MT5 Expert Advisors around your strategy, broker and risk requirements. Each project has an agreed scope, testing plan and individual quote.