← Script Marketplace
Open-source scriptindicator/v1

Supertrend

by Kodexius·@kodexius·

Follow ATR-based trend direction with a configurable Supertrend line and bullish or bearish markers.

#atr#signals#supertrend#trend
Supertrend chart preview
Open-source script. Everyone can inspect the source code, use the script on a chart, and save an editable copy.

About this script

An ATR-based Supertrend overlay with adjustable factor and period. The indicator follows the active trailing level and marks changes in trend direction directly on the chart.

Source code
mpl-2.0
// ATR-based trend-following overlay
indicator("Supertrend", { overlay: true });

const factor = input.number("Factor", 3, { min: 0.5, max: 10, step: 0.5 });
const atrLen = input.number("ATR period", 10, { min: 1, max: 100 });
const [lineValue, direction] = supertrend(factor, atrLen);
const bullish = crossover(direction.map((value) => -value), 0);
const bearish = crossunder(direction.map((value) => -value), 0);

plot(lineValue, { title: "Supertrend", color: "#22d3ee" });
signal(bullish, { position: "belowBar", shape: "arrowUp", color: "#34d399", text: "UP" });
signal(bearish, { position: "aboveBar", shape: "arrowDown", color: "#f87171", text: "DOWN" });

alertcondition(bullish, "Supertrend changed to bullish");
alertcondition(bearish, "Supertrend changed to bearish");

Release notes

Initial official release.