SuperCharting
Sign in Get started Account Open charts

Learn / Indicators

Supertrend indicator: ATR length, factor and trend alerts explained

How the Supertrend indicator works in SuperCharting: ATR Length and Factor, reading trend flips, its three built-in alerts and the Supertrend strategy.

Supertrend is a trend-following line drawn a set distance from price, using the Average True Range (ATR). It sits below price in an uptrend and above price in a downtrend, and it flips sides when price closes through it. In SuperCharting you add it from Indicators by searching "supertrend". It comes with TradingView's defaults (ATR Length 10, Factor 3), three alerts and a matching strategy you can backtest.

How Supertrend is calculated

For each bar, the script measures volatility with a 10-bar ATR and builds two bands around the bar's midpoint, (high + low) / 2:

While the trend is up, the line follows the lower band and can only rise or stay flat. While the trend is down, it follows the upper band and can only fall or stay flat. A close beyond the line flips the direction, and the line jumps to the other band.

The built-in draws two plots, Up Trend in green and Down Trend in red, with a light fill between the line and the middle of each candle body. Only one is visible at a time, so the colour of the line tells you the current direction.

How to add Supertrend in SuperCharting

  1. Open a chart, for example NSE:BANKNIFTY on the 15m interval.
  2. Click Indicators, type "supertrend" and click Supertrend (on the Indicators chip, not the strategy).
  3. Hover the legend and click the gear for Settings.
  4. On Inputs, set ATR Length (10) and Factor (3.0, changes in steps of 0.01).
  5. On Style, change the Up Trend and Down Trend colours or line width. You can also turn off the fills, or hide one direction.
  6. Click Ok.

Choosing the settings

As examples, some swing traders use 10 and 3 on daily NSE stocks. Some intraday traders on XAUUSD 5m try 10 and 2 for tighter lines. Treat these as starting points to test, not recommendations.

Reading Supertrend

These are descriptions of how the indicator is commonly read, not advice to buy or sell.

Supertrend alerts

Open the legend's More menu and choose Add alert on …. The built-in defines three conditions:

Set Trigger to Once per bar close so that a flip which reverses before the bar closes is not reported. Then set Expiration and your notifications. Each field is explained in price alerts.

An indicator alert runs the script with its default inputs, which means ATR Length 10 and Factor 3. If you trade other settings, or want the EMA filter described above, use a script of your own with the numbers you want as defaults:

//@version=6
indicator("Supertrend with EMA filter", "ST filter", overlay = true)
atrLen = input.int(10, "ATR length", minval = 1)
factor = input.float(3.0, "Factor", minval = 0.1, step = 0.1)
emaLen = input.int(200, "Trend filter EMA", minval = 1)
[st, dir] = ta.supertrend(factor, atrLen)
trendEma = ta.ema(close, emaLen)
plot(dir < 0 ? st : na, "Up trend", color.green, style = plot.style_linebr)
plot(dir > 0 ? st : na, "Down trend", color.red, style = plot.style_linebr)
plot(trendEma, "Filter EMA", color.gray)
flipUp = ta.change(dir) < 0 and close > trendEma
flipDown = ta.change(dir) > 0 and close < trendEma
plotshape(flipUp, "Flip up", shape.labelup, location.belowbar, color.green, text = "Up")
plotshape(flipDown, "Flip down", shape.labeldown, location.abovebar, color.red, text = "Down")
alertcondition(flipUp, "Supertrend up with trend", "Supertrend turned up above the filter EMA")
alertcondition(flipDown, "Supertrend down with trend", "Supertrend turned down below the filter EMA")

Save it in the Script Editor, add it from My scripts in the Indicators dialog, and create the alert from its legend menu as above. In this script dir is negative in an uptrend and positive in a downtrend, the same convention as the built-in.

Backtesting the Supertrend strategy

The Strategies chip has Supertrend strategy. It enters long when the direction flips up and short when it flips down, so it is always in the market after the first signal. Each entry uses 15% of equity, and ATR Length and Factor are the same inputs as the indicator.

  1. Add Supertrend strategy to a chart, for example NSE:RELIANCE 1D.
  2. Open the legend's More menu and choose Strategy Tester to see the report and list of trades. The Strategy Tester guide explains each figure.
  3. On the strategy's Properties tab, set Commission and Slippage to match your broker.
  4. To try a range of factors, choose Optimise strategy… in the same menu. Read the backtesting guide on avoiding settings that only fit the past.

Past results do not guarantee future results.

Frequently asked questions

Does Supertrend repaint?

Values on closed bars stay fixed. On the live bar, the line and its direction can change until the bar closes. That is why alerts set to Once per bar close are the usual choice.

Why are there two plots instead of one line?

The script plots Up Trend and Down Trend separately so each has its own colour. Hiding one on the Style tab shows only uptrend or only downtrend lines.

What is the difference from a moving average?

A moving average follows the average price. Supertrend follows volatility-based bands and only moves in the trend's favour until it flips, so it works more like a trailing stop.

Can I use Supertrend on forex and crypto?

Yes. It only needs high, low and close, so it works on EURUSD, XAUUSD or BTCUSD on any interval.

Try it on a live chart

SuperCharting runs in your browser: charts, Pine-compatible scripts, the Strategy Tester, alerts and the screener, with Indian and global markets.

Create a free account More guides