What Is Supertrend? —
Tuning it, and why it fits automated trading signals
You slap Supertrend onto TradingView. The line is green — long. The line flips red — short. You wire the flip as an alert condition and point the webhook (the HTTP notification TradingView fires when the alert triggers) at TVSBot or any other execution endpoint. First time you run it live, two things happen.
First: the bar hasn't closed, and the signal already went out. Second: the same bar flips back later, and by the time you notice, the position has reversed twice and you've already paid a round of fees. Supertrend isn't broken and your strategy logic isn't wrong — it's that its "answer right now" personality doesn't line up with the cadence of automated execution.
alertcondition() plus the UI's "Once Per Bar Close" trigger mode, or barstate.isconfirmed inside the condition. Both filter out the intra-bar flicker. That's the single most important sentence in this piece.What Supertrend Is Computing — ATR Sets the Width, Close Sets the Direction
Supertrend has two layers. The first is the base band: take each bar's midpoint (high + low) / 2 as the centerline, then push multiplier × ATR in each direction to get the upper and lower rails. ATR is Average True Range, a measure of how much price has been moving lately — a high ATR means volatile, so the band is wide; a low ATR means calm, so the band is tight.
The second layer is direction lock: whether the plotted line is the upper or lower rail depends on the current trend. When short, it plots the upper rail, which can only step down (if a new bar computes a wider upper rail, it keeps the tighter one). When long, it plots the lower rail, which can only step up. The flip trigger is simple: close crosses the current line. Close falls through the lower rail, flip short; close pushes above the upper rail, flip long.
Two Parameters: ATR Period and Multiplier
Supertrend has two knobs. Everything else is derived from these.
| Parameter | What it does | Turn it up | Turn it down |
|---|---|---|---|
| ATR period | Sample length (in bars) for ATR | Smoother volatility reading, slower to react | More sensitive to recent moves, flips more often |
| multiplier | Distance from center to rails (in ATRs) | Wider band, fewer flips, tolerates noise | Tighter band, denser signals, catches small moves |
Supertrend's two parameters and what each one controls. (Verified 2026-08.)
TradingView's built-in ta.supertrend(factor, atrPeriod) defaults to ATR period 10, multiplier 3. TVSBot's Pine templates page uses the same pair — this is where the community starts, not because it's "best," but because it's the shared starting point. Want it more conservative, push multiplier to 4 or 5; want it more sensitive, drop it to 2.
//@version=5
strategy("TVSBot SuperTrend", overlay=true)
atrPeriod = input.int(10, "ATR period")
factor = input.float(3.0, "SuperTrend multiplier")
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
longCondition = ta.change(direction) < 0 // flip from short to long
shortCondition = ta.change(direction) > 0 // flip from long to short
if longCondition
strategy.entry("Long", strategy.long, alert_message='{"side":"buy"}')
if shortCondition
strategy.entry("Short", strategy.short, alert_message='{"side":"sell"}')That's the official TVSBot Pine template, source /docs/pine-templates. ta.supertrend()'s first return value is the line price; the second is direction — -1 is long, 1 is short. So ta.change(direction) < 0 means "this bar flipped from short to long."
Why It Beats RSI/MACD as an Automation Signal
Oscillators — RSI (Relative Strength Index), MACD (fast/slow moving-average spread) — produce continuous values. RSI is a number between 0 and 100; MACD histogram is a shifting spread. To turn either into an automated signal, you have to draw your own line on top (buy when RSI drops below 30, buy when the histogram crosses zero), and that line gets crossed back and forth in chop.
Supertrend is different: it emits discrete state — only up and down, and the flip is a single unambiguous event. There's no "almost flipping" or "about to flip." That matters for webhooks, because a webhook only understands "triggered" or "not triggered" — it can't transmit an in-between state like "getting close."
| RSI / MACD | Supertrend | ||
|---|---|---|---|
| Signal shape | Continuous value | Discrete direction | |
| Flip criterion | Cross a custom threshold | Cross the current trailing band | |
| Stop-loss location | Defined separately | The indicator line itself | |
| Behavior in chop | Noisy, misfires often | Few flips, but the full leg | |
| Fit as webhook trigger | Needs an added filter | The flip is the trigger |
To be clear: this doesn't mean Supertrend is inherently "more accurate." It's that structurally its interface lines up with automated execution better — you don't need much wrapper logic to turn it into a clean signal source.
But — Signals Flicker Before the Bar Closes
Here is how Pine Script computes "the current bar": on every incoming tick, it recomputes as if the bar just closed at that price. So the current segment of Supertrend you see on the chart is being overwritten in real time.
direction value on the current bar can be different on every tick until close. Set your alert to "Once Per Bar" and it fires the first time the condition is met — even if that only lasted half a second. The actual direction at the moment of close could be the opposite.Pine has two built-in ways to filter that. In the TradingView UI, alertcondition() lets you pick Once Per Bar Close, which fires only when the condition is met at bar close. And barstate.isconfirmed — a built-in that's only true at bar close — can go straight into your if condition to filter intra-bar flicker.
The template above uses the strategy.entry path via alert() / alert conditions, so the normal path relies on the trigger mode you set when creating the alert. If you pull out a custom condition via alertcondition(), you have to pick the close option — otherwise everything above is wasted.
Four Things to Check Before Pointing a Webhook at It
If any of the following isn't in place, your Supertrend signals will either flicker intra-bar or behave differently from what you expect. Get all of them green before going live.
Once Per Bar Close as the alert trigger mode?direction in the Data Window bounce around intra-bar?- When creating the alert, pick Once Per Bar Close, not Once Per Bar. The latter fires the first moment the condition is met, and intra-bar flip-flops are the norm.
- If you write your own
alertcondition(), or your strategy entry/exit conditions can't rely on the UI, addand barstate.isconfirmedinside the condition. That's Pine's recommended intra-bar filter. - Use TradingView's Data Window (top-right
{}icon → Data Window) to watch thedirectioncolumn. Stare at a single bar as it forms; if the value flips back and forth, so will your alerts. - In the webhook payload,
{{strategy.order.action}}is the order direction TradingView had at the exact moment of trigger. What you send before the bar closes isn't necessarily what you'd send after — so the first item is non-negotiable, otherwise this payload is lying to you. - In the TVSBot dashboard, enable dry-run (runs the execution flow without placing real orders) for a few days. Compare each Supertrend flip on the chart with the timestamp the dashboard received. Any drift, go back to the first three.
An Honest Aside: What Supertrend Isn't Good At
Supertrend performs best in single-direction trends — once locked, it just rides the wind. Flipped around, in choppy ranges it takes slap after slap: no matter how wide you set the band, price bouncing inside eventually pushes through a line, flips, and flips back. That's not bad tuning; it's how the indicator is built.
It also only gives you direction, not size. Short-to-long is buy; long-to-short is sell. But how much to buy, whether to add on, when to take profit — those are all separate. In the TVSBot payload, margin_pct, tp_pct, and sl_pct are the fields you have to decide on top of the Supertrend signal (how to size positions in webhook-driven automation breaks that apart in more detail). The indicator doesn't know your account size or your risk appetite.
Another thing users routinely miss: Supertrend's signal is scoped to a timeframe. Parameters tuned on a 4H chart don't transfer to 15m as-is. Multiplier 3 is steady on 4H; on 5m it may flip every two hours. Tune parameters against the timeframe you plan to run, or you'll think you're running a conservative strategy while actually running a noise machine.
FAQ
Can I use the defaults (ATR 10, multiplier 3) as-is?
ta.supertrend() and the TVSBot template default, but whether it's appropriate depends on your timeframe and the asset's volatility. Use TradingView's Strategy Tester to backtest ATR period 7–14 and multiplier 2–5, and pick the pair whose max drawdown you can stomach.Why did the line flip color, but the direction value didn't change?
direction at that moment.Does Once Per Bar Close make me enter one bar late?
Can Supertrend be combined with other indicators?
If I send Supertrend webhooks to TVSBot, can I place multiple orders from the same Pine file?
strategy()'s pyramiding parameter defaults to 0, meaning "only one entry allowed per direction — subsequent same-direction strategy.entry() calls get rejected." To actually add on, you have to explicitly write pyramiding=2 (or higher) in the strategy(...) declaration. To hold multiple independent positions, use TVSBot's strategy field in the payload to distinguish strategies, or run a separate Pine file per position. That's not a Supertrend thing — it's a Pine position-sizing pitfall.Get started
Route your Supertrend flip signals into the exchange — TVSBot uses your own API keys, supports dry-run, and puts risk controls in your hands. Seven exchanges supported.
Get started for free- ATR, in detail — sizing positions with volatility
- Moving averages, in detail — SMA, EMA, and the 200-day line
- Pine Script alerts have no memory: why naive trigger logic breaks automation
- TradingView Webhook, in detail — from zero to automated trading
- How to size positions in TradingView webhook automation