SuperTrend in Pine Script
A trailing line set a multiple of ATR from the bar midpoint that ratchets behind price and flips to the other side when price closes through it, so the chart is always in one of two states.
Definition
SuperTrend is a trailing stop line drawn a multiple of the average true range away from the midpoint of each bar. In an uptrend it sits below price and can only rise; in a downtrend it sits above price and can only fall. When price closes through the line, the trend flips and the line jumps to the other side. It belongs to the trailing trend lines family with Parabolic SAR and the Chandelier Exit, and it is popular because it gives one unambiguous state per bar with no lines to compare.
The line works because it combines a volatility buffer with a ratchet. The buffer, 3 ATR by default, is wide enough that normal pullbacks do not reach it, so the state survives the noise inside a trend. The ratchet means the line never gives ground: each bar it moves closer to price or stays put, so the stop tightens as the trend progresses and the eventual flip happens near the end of the move rather than long after it. The result is a trend definition that is late at the start and reasonable at the end.
The standard settings are an ATR length of 10 and a multiplier of 3; 7 and 3 or 14 and 2 are common variants. The library's implementation uses the platform's built-in calculation with those defaults, draws the line green under price while the trend is up and red over price while it is down, and marks Long on the confirmed bar of a flip up and Short on a flip down. The strategy version enters on every flip, is always in the market in the trend's direction, and can add an ATR target.
On the chart the line looks like a staircase under a rising market: flat while price pauses, stepping up as new highs raise the midpoint, never stepping down. A pullback that closes through the stair flips the colour, and the new line appears above price a full buffer away. In a trend that gives a few flips a year; in a range the flips come every few bars and each one is a small loss, which is the shared weakness of every trailing line.
Reading the chart
SuperTrend has two states and one event, so reading it is about the quality of each flip and the distance of the line from price.
- Confirm the settings: an ATR length of 10 and a multiplier of 3 is the standard. A lower multiplier hugs price and flips often; a higher one holds the state through deeper pullbacks.
- Read the state. A green line under price means the trend is up on this timeframe and longs are permitted; a red line over price means down. There is no neutral state.
- Measure the distance from price to the line. Right after a flip it is a full 3 ATR; deep into a trend it can shrink as the line ratchets, which is where the flip risk rises.
- Judge the flip by its context. A flip up after a long red run and a higher low is a trend change; a flip 3 bars after the last flip is a range, and the next flip will reverse it.
- Use the line as the stop. The distance from entry to the line is the risk of the trade, so a flip taken with the line far away needs a smaller size than one taken near it.
- Check a higher timeframe. A 15 minute flip up under a red daily SuperTrend is a bounce; the same flip under a green daily line is a continuation entry.
The maths
Two bands are set a multiple of ATR either side of the bar midpoint, each ratchets in the trend's direction, and the active band flips when the close crosses it.
The ratchet is the whole design: the lower band in an uptrend can rise or stay flat but never fall, so the line tightens as the move matures and the flip is a true stop-out.
A flip resets the line to the opposite basic band, a full multiplier of ATR from the midpoint, which is why the new line starts far from price.
The ATR uses the same smoothing as the platform's built-in average true range; a different ATR method shifts the line slightly.
The library's strategy exits the open position on the opposite flip and reverses; with a target above 0 it also closes at the entry close plus or minus that many ATR.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| ATR multiplier | 3 | Lower values pull the line closer to price, which flips sooner in reversals and far more often in ranges; higher values keep the state through deeper pullbacks and exit later. |
| ATR length | 10 | A shorter ATR makes the buffer react to the last few bars' volatility; a longer one keeps the buffer steady through a volatility spike. |
| Target (ATR multiples) | 0 (off) | In the strategy, a target of 2 or 3 ATR caps winners and raises the hit rate; off, the opposite flip is the only exit and the long trends pay. |
In practice
- As a trend state: read the colour before anything else; the filter keeps only setups in its direction. Green under price permits longs; red over price permits shorts.
- As a trailing stop: the rule holds a trend trade with the stop at the line, which rises with the trend and never loosens. The library's indicator marks the flip that ends the position.
- As a systematic strategy: the strategy version flips with the line, always in the market, and is a fair baseline for a trend system on daily or 4 hour charts.
- As a filter for faster tools: the filter passes a 9/21 cross or an oscillator trigger only while SuperTrend agrees with it, which removes most counter-trend trades mechanically.
- As a higher-timeframe bias: a daily SuperTrend read on an intraday chart gives the permitted side for the session, with the same step behaviour as any higher-timeframe filter.
- As a flip alert: the indicator's alerts fire once per confirmed flip, so a watchlist of charts can report its trend changes without anyone watching every chart.
Where it goes wrong
- Trading every flip in a range. Flips a few bars apart cancel each other; require the line to have held for a stretch, or add a strength filter such as ADX above 25.
- Tightening the multiplier to catch turns faster. Below 2 the line lives inside the noise and the flip count explodes; if you want earlier exits, use a faster tool for exits and keep SuperTrend for state.
- Placing the stop inside the line. The line is the stop the tool implies; a stop tighter than it will be hit by pullbacks the state was designed to survive.
- Ignoring the entry distance. Right after a flip the line is 3 ATR away, so the first trade of a new trend carries the largest risk; size for it or wait for the line to ratchet closer.
Compared with
Parabolic SAR. SAR is also a trailing stop that flips, but it accelerates towards price as the trend ages regardless of volatility. SuperTrend keeps a volatility buffer and only tightens when price makes progress, so it survives long pauses that SAR stops out.
Chandelier Exit. The Chandelier Exit hangs a multiple of ATR below the highest high, which is a pure trailing stop with no flip logic. SuperTrend measures from the bar midpoint, ratchets the same way and adds the flip that turns it into a two-sided trend state.
Moving Average. A moving average moves both ways every bar and can be crossed many times without a regime change. SuperTrend only moves in the trend's favour and only flips on a close through it, so it gives a cleaner but later state.
Keltner Channels. Keltner Channels use the same ATR multiple around an EMA, but as a symmetric envelope that shows stretch. SuperTrend uses one side of that envelope at a time, ratcheted, as a stop and state line.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
What are the best SuperTrend settings?
The standard is an ATR length of 10 and a multiplier of 3, and it is a fair default on most timeframes. Use a multiplier of 2 with a 14 period ATR for faster flips on daily charts of calm instruments, and 3 or 4 on crypto and other fast markets so normal pullbacks do not flip the state.
Does SuperTrend repaint?
No. The bands are built from closed bars, the ratchet uses the previous bar's values, and the library's script marks a flip only on a confirmed bar. The line on the current bar can move while that bar forms, and a flip that appears mid-bar is not a signal until the close.
Is SuperTrend good for scalping?
Not on its own. On 1 and 5 minute charts the flips come every few bars in any pause and each one costs spread and slippage. It works better as the state filter for a faster entry tool, or on 15 minute and higher charts where a flip means something.
Why does the line jump so far after a flip?
Because a flip resets it to the opposite basic band, a full multiplier of ATR from the bar's midpoint. The old line was ratcheted close to price; the new one starts at the full buffer so the new trend has room to breathe. That first stretch is also the largest risk of the trade.
How is SuperTrend different from a moving average?
A moving average is a smoothed price that moves both ways and is crossed constantly; SuperTrend is a stop line that only moves in the trend's favour and flips only on a close through it. The average is better for level and pullback entries, SuperTrend for defining the state and the exit.
Can I use SuperTrend as a strategy?
Yes. The library's strategy enters long on a flip up, short on a flip down, closes the opposite position on each flip, and can add an ATR target. Always in the market, it tends to gain in trends and lose in ranges, so test it with a strength filter and with long only in bull regimes.