All free tools

Trend indicator

Supertrend Calculator

Compute one Supertrend step from the current bar, its ATR, the factor, and the previous final bands. It follows the same rules as TradingView's ta.supertrend.

Supertrend line
98.000
The lower band in an uptrend, the upper band in a downtrend.
Direction
Uptrend (-1)
Pine Script sign: -1 is an uptrend, 1 is a downtrend.
Final upper band
117.000
Can only move down while the trend holds.
Final lower band
98.000
Can only move up while the trend holds.

How the Supertrend is calculated

The Supertrend builds two bands around the midpoint of each bar, (high + low) / 2. The basic upper band is that midpoint plus the factor times ATR, and the basic lower band is the midpoint minus the factor times ATR.

The final bands are smoothed so they only move one way while a trend lasts: the lower band can rise but not fall, and the upper band can fall but not rise, unless the previous close broke through that band. The direction flips to a downtrend when the close drops below the final lower band, and to an uptrend when the close rises above the final upper band. The plotted line is the lower band in an uptrend and the upper band in a downtrend.

What the inputs control

A larger factor places the bands further from price, so the line flips less often and reacts more slowly. A shorter ATR length makes the bands respond faster to changes in volatility. How you choose these settings is your own decision, and the line describes past price movement only.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

This tool shows a single step, but the Supertrend depends on every earlier bar because each final band carries over from the last. In Pine Script, ta.supertrend(factor, atrPeriod) returns the line and direction for every bar, so you can plot it or build alerts and filters around it.

Pine Script v6
//@version=6
indicator("Supertrend", overlay=true)

atrPeriod = input.int(10, "ATR Length", minval=1)
factor = input.float(3.0, "Factor", minval=0.01, step=0.1)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

upTrend = direction < 0
plot(upTrend ? supertrend : na, "Up Trend", color=color.green, style=plot.style_linebr)
plot(upTrend ? na : supertrend, "Down Trend", color=color.red, style=plot.style_linebr)

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

Related free calculators

From the blog

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.