Skip to content

One line that sits below price in a rise and above it in a fall, and only ever moves in the trend’s favour.

Supertrend puts a band multiplier × ATR above and below the middle of each bar. In a rise it shows the lower band, which can rise but not fall; in a fall, the upper band, which can fall but not rise. When the close goes through the band, the trend flips and the other band takes over.

Traders use the line as a trailing stop and its side of price as the trend: hold longs while it is below the close and shorts while it is above. A larger multiplier flips less often and gives back more before it does.

middle = (HIGH + LOW) / 2
basic upper = middle + multiplier × ATR(periods)
basic lower = middle − multiplier × ATR(periods)
upper = basic upper if it is lower than the previous upper, or the previous close was above the previous upper; else the previous upper
lower = basic lower if it is higher than the previous lower, or the previous close was below the previous lower; else the previous lower
Supertrend = lower in a rise, upper in a fall

The ATR is Wilder’s. The first trend is a fall, as TradingView’s ta.supertrend starts.

Call: supertrend(periods, multiplier)

Setting Chart default
periods: ATR Periods 10
multiplier: Multiplier 3

What you get: a number.

Warm-up: with supertrend(10, 3), it asks for 0 bars of history and a run-up of 40, and its first value came on bar 11 of the example data.

Supertrend drawn by its own code on example prices

The prices are made up, hourly, and the same on every page, so the chart shows how the indicator behaves, not how a market behaved.

function onIntervalClose() {
const line = supertrend(10, 3);
if (line !== null && line < CLOSE && OPEN_POSITIONS_COUNT === 0) {
openPosition("BUY", { quantity: 10000, stopLossPips: 30 });
}
}