Bentrix Docs
HomePricingDashboard

SuperTrend

Trend & channelsoverlay2 linesin every package

A band at the median price plus and minus a multiple of ATR, which only ever moves in the trend's favour and flips side when a close crosses it.

It measures a volatility-scaled trailing level and the side that follows from it. The readings are the side and the flip bar. Built for Bentrix: no MT5 handle and no TA-Lib function exists to gate it against.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
bar —O — H — L — C —up trend —down trend —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars. SuperTrend has no value on the first 10 — the bars it needs before it can answer — and its first value stands on bar 11. Counting the conditions the study declares on these bars: the trend line turns up once; the trend line turns down once. Press a condition under the figure to see each place marked.

02Its parts, named

The line, fallingdrawn in this colour while the studypoints downWarm-upno value on the first 10 bars: thestudy needs them before it cananswerThe line, risingdrawn in this colour while the studypoints upThe bars it readseach bar's open, high, low and close
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

One line, below price in a rise and above it in a fall, that only moves in the direction of the move and switches side when price closes beyond it.

04Where it comes from

Olivier Seban popularised SuperTrend in France in the late 2000s. It is an ATR band that is only allowed to move toward price, with a flip when the close crosses it — a trailing stop drawn as a line.

05The formula

basic upper=H+L2+m·ATR(N),basic lower=H+L2−m·ATR(N)
H, Lthe bar's high and low
mthe multiplier — 3 by default
ATR(N)the average true range over N bars — 10 by default

The lower line is kept from falling while the trend is up and the upper from rising while it is down; when the close crosses the active line, the trend flips. Defaults: ATR 10, multiple 3.

06A worked example

Take a multiplier of 3, a bar with a high of 102.00 and a low of 100.00, and an ATR of 1.50.

The bar's middle is (102.00 + 100.00) / 2 = 101.00, and the basic bands are

  • upper = 101.00 + 3 × 1.50 = 105.50
  • lower = 101.00 − 3 × 1.50 = 96.50

In a rising phase only the lower band is drawn. If the previous bar's lower band was 97.10, the new one stays 97.10: the band never moves away from price, only toward it. Had the new basic lower band been 97.60, the line would step up to 97.60.

The phase flips when a bar closes below the lower band; the upper band is then drawn instead.

On real bars: take eight that rise, with highs 21, 22, 24, 24, 25, 26, 26, 27, lows 18, 19, 20, 21, 21, 23, 23, 23 and closes 20, 21, 23, 22, 24, 25, 24, 26, a period of 3 and a multiplier of 1. On the seventh bar the middle is 24.50 and the ATR 3.247, so the lower band is 24.50 − 3.247 = 21.25. On the last bar the middle is 25.00 and the ATR 3.498: the basic lower band, 25.00 − 3.498 = 21.50, is above 21.25, so the line steps up to 21.50.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("SuperTrend", overlay = true)
length = input.int(10, "ATR length")
multiplier = input.float(3.0, "Multiplier")
// The average true range, Wilder's way.
trueRange = math.max(high - low, math.abs(close[1] - high), math.abs(close[1] - low))
atr = ta.rma(trueRange, length)
// Two bands around the middle of the bar, `multiplier` ATRs away.
middle = (high + low) / 2
basicUpper = middle + multiplier * atr
basicLower = middle - multiplier * atr
var float upper = na
var float lower = na
var int trend = 1
if not na(atr)
    if na(upper)
        upper := basicUpper
        lower := basicLower
        trend := 1
    else
        // A band only moves toward the price, unless the last close went beyond it.
        if basicUpper < upper or close[1] > upper
            upper := basicUpper
        if basicLower > lower or close[1] < lower
            lower := basicLower
        // The trend flips when the close crosses the band on the other side.
        if trend == 1 and close < lower
            trend := -1
        else if trend == -1 and close > upper
            trend := 1
// In an up-trend the line is the lower band; in a down-trend, the upper one.
plot(na(atr) or trend != 1 ? na : lower, "Up trend")
plot(na(atr) or trend != -1 ? na : upper, "Down trend")

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

The line's side is read as the trend's direction; the line itself is often used as a trailing stop level.

How a flip fails. A flip says a close crossed a band three ATRs from the middle. In a range that is half as wide as the band, the line flips at the worst place on both sides, repeatedly.

How the flat steps fail. A long flat stretch of the line is read as a level price respected. It is flat because the band is not allowed to retreat — the market may simply not have come near it.

09In different markets and timeframes

SuperTrend is an ATR band that never retreats, flipping when the close crosses it. In trends it gives long flat-stepped runs; in a range narrower than its band it flips on both sides.

10With other studies

Read beside the ATR it is built from and beside a longer-timeframe SuperTrend for the larger direction.

11What it does not tell you

!

Like every trailing line, it flips repeatedly in a sideways market and describes the move behind it.

12Inputs and defaults

SuperTrend (3, 10)settings card
1Multiplier3
2Period10
3TimeframeChart
4Wait for the candle to closeOn
  1. 1
    Multiplier — 3How many ATRs the band stands from the bar's middle. Larger: fewer flips, each further from the turn.
  2. 2
    Period — 10The ATR's period. Shorter: the band's distance follows each wide bar.
  3. 3
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  4. 4
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

The settings in use

  • In use10 and 3 are the common pair; 7 and 3, or 10 and 2, flip sooner.

13Limits and common misreadings

Always in one phase, like the Parabolic SAR.

Decided on the close: an intrabar spike through the line does not flip it, a close a tick beyond does.

Start-dependent for its first phase.

14Conditions an alert or a strategy can watch

the trend line turns up eventthe trend line turns down event

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

15Practise it in the laboratory

Put SuperTrend (10, 3) on a chart; replay a trend and then the range after it, and compare the distance between flips with the width of the range.

Open the laboratory

17In Bentrix

  • From the menu: a chart's Indicators button › Trend & channels › SuperTrend, or type SuperTrend in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

18From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "supertrend"}).

The study, as a chart files it

This is a new SuperTrend’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "custom",
  "kind": "supertrend",
  "settings": {
    "mult": 3.0,
    "period": 10,
    "shape": "super_trend"
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "custom",
      "kind": "supertrend",
      "settings": {
        "mult": 3.0,
        "period": 10,
        "shape": "super_trend"
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "custom", "kind": "supertrend", "settings": {"mult": 3.0, "period": 10, "shape": "super_trend"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "custom", "kind": "supertrend", "settings": { "mult": 3.0, "period": 10, "shape": "super_trend" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "custom", ["kind"] = "supertrend", ["settings"] = new Dictionary<string, object?> { ["mult"] = 3.0, ["period"] = 10, ["shape"] = "super_trend" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "custom", "kind": "supertrend", "settings": map[string]any{"mult": 3.0, "period": 10, "shape": "super_trend"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "custom", "kind", "supertrend", "settings", obj("mult", 3.0, "period", 10, "shape", "super_trend"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "custom"}, {"kind", "supertrend"}, {"settings", Json::Object{{"mult", 3.0}, {"period", 10}, {"shape", "super_trend"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "custom", "kind" => "supertrend", "settings" => Dict{String,Any}("mult" => 3.0, "period" => 10, "shape" => "super_trend")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "custom", kind = "supertrend", settings = list(mult = 3.0, period = 10, shape = "super_trend")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "custom", "kind": "supertrend", "settings": {"mult": 3.0, "period": 10, "shape": "super_trend"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
lineWhat it is
TrendUpup trend
TrendDowndown trend

In a strategy

Filed under a key of your choice in a strategy document’s studies — here supertrend: {"supertrend": {"applied": "close", "convention": "custom", "kind": "supertrend", "settings": {"mult": 3.0, "period": 10, "shape": "super_trend"}}} — its rules can name:

WriteWhat it is
supertrend.trend_upthis line, as a value in a compare
supertrend.trend_downthis line, as a value in a compare
{"cond": "supertrend:trend.turns_up"}a condition it declares itself
{"cond": "supertrend:trend.turns_down"}a condition it declares itself

19Sources

  1. Kirkpatrick, Charles D. & Dahlquist, Julie R. Technical Analysis: The Complete Resource for Financial Market Technicians, 2nd ed. FT Press, 2010 (average true range bands).
  2. Seban, Olivier. Tout le monde mérite d'être riche. Maxima, 2008.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed