Supertrend
Is the trend up or down, and where would it flip?
A line a few ATRs from the price that sits below it in an uptrend and above it in a downtrend, flipping when a close goes through it.
Supertrend on a chart of past prices
Settings: move a slider and the chart redraws
How many days of price swings set the line's distance.
Bigger: the line sits further away, so fewer and later flips.
What it measures
Supertrend draws a line at a set distance from the price: below it while the trend is up (green), above it while the trend is down (red). The distance is a multiple of the ATR, the stock's average daily swing (see the ATR lesson), so a jumpy stock gets more room than a calm one.
The line only moves in the trend's direction: in an uptrend it can rise but never fall. When a close finally lands on the other side of it, the trend flips and the line jumps to the other side of the price.
It is popular with Indian traders because it gives one clear answer, up or down, and a ready-made stop-loss level.
How traders read it
- Green line under the candles: uptrend. Red line over them: downtrend.
- A flip, where the colour changes, is the classic signal: buy on a flip to green, sell on a flip to red. Marked on the chart.
- Many traders use the line itself as their stop-loss: it is the level where the trend would flip.
- A bigger multiplier keeps the line further away: fewer flips, later exits, bigger losses when wrong. A smaller one hugs the price: earlier exits, more false flips.
The traps
Late by design
It flips only after a close beyond a line several ATRs away, so it gives back part of every move before it exits.
Sideways chop
In a range the price keeps closing through the line, and each flip is a losing trade plus costs.
Gaps jump the line
The line is a level for the close. A stock that gaps down at 9:15 am can open well below it, so a stop-loss placed there fills lower.
Test the classic rule: Supertrend flip
Waiting for prices…
Quick check
Waiting for prices…
Use it in a script
function run(bars, ta, helpers) {
const st = ta.supertrend(bars, 10, 3); // .trend is 1 (up) or -1 (down)
const signals = [];
for (let i = 0; i < bars.length; i++) {
if (st[i].trend === 1) signals.push(helpers.buy(i)); // uptrend: be in
else if (st[i].trend === -1) signals.push(helpers.sell(i)); // downtrend: be out
}
return helpers.finalize(signals); // keeps the first of each run: the flips
}This is the rule tested above, with the settings on your sliders, and it gives exactly the same buy and sell candles. Paste it into the Scripts drawer of the chart workbench, or save it and compare it across stocks in the Strategy Lab. New to scripts? The Writing strategies track starts from zero.
In the reference:ta.supertrendta.wilderAtr