TradingView Supertrend: settings and confirmed signals
Add Supertrend from Indicators. Its ATR length and factor control the bands; a direction change identifies a flip.
In Pine Script, ta.supertrend() returns a line and a direction: negative means uptrend, positive means downtrend. A trend state can last many bars. The example below marks only direction changes confirmed at the chart bar close, with optional EMA and ADX filters. These rules do not establish profitable settings or remove sideways-market whipsaws.
Add Supertrend to a TradingView chart
- Open Indicators, search for Supertrend, and select TradingView's built-in indicator.
- Open Settings and check ATR Length and Factor. Match the calculation timeframe to your chart when comparing it with this example.
- Use the example's ATR length 10 and factor 3 as a comparison baseline, then change one input at a time.
Supertrend uses ATR to set volatility bands around the midpoint of each bar. It retains band values according to the previous bands and close, then selects an active band for the current direction. See TradingView's Supertrend calculation.
This tutorial and its code are available to read and copy. Pineify product access and TradingView account limits are separate. Browse other studies in the TradingView indicators directory.
Why Traders Use This Indicator
- Inspect the current trend state and the bar on which it changes.
- Define repeatable alert conditions using ATR-based bands.
- Study an active band as a possible exit reference, with separate order and risk rules.
| Parameter | Default | Description |
|---|---|---|
| ATR length | 10 in this example | Number of chart bars used by ATR. Changing the length alters its volatility estimate; 10 bars is not necessarily 10 days. |
| Factor | 3.0 in this example | Multiplier applied to ATR before constructing the bands. A larger factor widens the basic bands; the active line also depends on prior band values and trend state. |
| Optional EMA filter | Off; length 200 | When enabled, an upward flip needs close above the EMA and a downward flip needs close below it. It changes accepted signals, not the Supertrend calculation. |
| Optional ADX filter | Off; threshold 20 | Uses ADX from ta.dmi(14, 14). The threshold is an example to compare, not a validated cutoff. ADX measures directional strength, not direction or volatility. |
| Signal timing | Confirmed chart bar close | Both labels and alert conditions require barstate.isconfirmed. The live Supertrend line can still update while the bar is open. |
Read the bands, state and direction changes
The basic bands are hl2 + factor × ATR and hl2 - factor × ATR. The final upper band keeps its prior value unless the new basic upper band is lower or the previous close was above the previous upper band. The lower band uses the corresponding opposite tests.
When the previous active band is the upper band, a close above the current final upper band selects the lower band. When the lower band is active, a close below the current final lower band selects the upper band. This memory means the active line is not simply a fixed ATR distance from every close.
[stValue, direction] = ta.supertrend(factor, atrLength) supplies both outputs. Use direction < 0 for an uptrend and direction > 0 for a downtrend. See the ta.supertrend reference for the function's arguments and direction convention.
Signal Interpretation
- State: negative direction describes an uptrend on this bar. It does not mean a new upward signal occurs on every bar.
- Upward flip: direction was positive on the previous bar and is negative now. A downward flip reverses those signs.
- Confirmed flip: the direction change remains present on the closing update. This example also requires a valid Supertrend value on both bars to avoid an initialization marker.
- Filtered flip: enabled EMA and ADX conditions must pass on that same closing update. A rejected flip is not queued for a later bar.
The repainting documentation explains why the open bar can change. The Pine alerts documentation distinguishes alert conditions from running alerts. After adding this script, create an alert for Bullish flip or Bearish flip and choose Once Per Bar Close. Recreate alerts after changing inputs, code, symbol or timeframe because existing alerts retain their saved configuration.
Combining with Other Indicators
EMA and ADX are optional experiments here. They reduce the set of accepted flips and may exclude useful signals as well as unwanted ones. ADX comes from the third output of ta.dmi(); this script does not call a nonexistent ta.adx() function.
To compare settings, keep symbol, exchange, timeframe, session and date range fixed. Start with both filters disabled and compare ATR length 10 with factors 2 and 3, then test a different ATR length while holding factor fixed. Record flip count and the bars affected. The numbers are proposed test inputs; no results are claimed.
For performance testing, create a strategy with explicit entries, exits, sizing, commission and slippage. Reserve a later period for evaluation without retuning. Inspect trade count, drawdown and net results together. Pineify Strategy Optimizer can help compare strategy input combinations; an indicator alone has no Strategy Tester trade results.
Writing Pine Script Manually
Challenges of Manual Coding
Reversing the built-in direction signs makes bullish and bearish conditions exchange roles.
Checking only the current direction repeats a state instead of detecting a new event.
An alert title saying Bar Close does not enforce confirmation in its condition.
Filters applied after a missed flip can accidentally create a different delayed-entry rule.
//@version=6
indicator("Supertrend confirmed flips [Pineify]", overlay=true)
atrLength = input.int(10, "ATR length", minval=1)
factor = input.float(3.0, "Factor", minval=0.1, step=0.1)
useEma = input.bool(false, "Enable EMA filter")
emaLength = input.int(200, "EMA length", minval=1)
useAdx = input.bool(false, "Enable ADX filter")
adxThreshold = input.float(20.0, "Minimum ADX", minval=0, maxval=100)
[stValue, direction] = ta.supertrend(factor, atrLength)
emaValue = ta.ema(close, emaLength)
[diPlus, diMinus, adxValue] = ta.dmi(14, 14)
// Negative direction is an uptrend; positive direction is a downtrend.
isUptrend = direction < 0
isDowntrend = direction > 0
ready = not na(stValue) and not na(stValue[1])
upFlip = ready and isUptrend and direction[1] > 0
downFlip = ready and isDowntrend and direction[1] < 0
// Filters must pass on the flip bar. Rejected flips are not delayed.
emaLongOk = not useEma or close > emaValue
emaShortOk = not useEma or close < emaValue
adxOk = not useAdx or adxValue >= adxThreshold
confirmedUp = barstate.isconfirmed and upFlip and emaLongOk and adxOk
confirmedDown = barstate.isconfirmed and downFlip and emaShortOk and adxOk
// Lines update on the open bar; markers wait for its close.
plot(isUptrend ? stValue : na, "Uptrend", color=color.green, linewidth=2, style=plot.style_linebr)
plot(isDowntrend ? stValue : na, "Downtrend", color=color.red, linewidth=2, style=plot.style_linebr)
plot(useEma ? emaValue : na, "EMA filter", color=color.orange)
plotshape(confirmedUp, title="Confirmed upward flip", text="UP", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.tiny)
plotshape(confirmedDown, title="Confirmed downward flip", text="DOWN", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.tiny)
alertcondition(confirmedUp, title="Bullish flip", message="Confirmed Supertrend upward flip: {{ticker}} {{interval}} at {{close}}")
alertcondition(confirmedDown, title="Bearish flip", message="Confirmed Supertrend downward flip: {{ticker}} {{interval}} at {{close}}")Maintenance Note: This example uses chart-timeframe data only. Its bar-close gate applies to markers and alert conditions, not the live plots. Validate higher-timeframe requests separately before adding them; chart-bar confirmation does not confirm a higher-timeframe bar.
Build with Pineify Visual Editor
Pineify lets you configure supported indicators and export Pine Script. Available settings and plan requirements vary by indicator. Compare the generated rules with the example before using its signals.
| Feature | Manual Pine Script | Pineify Visual Editor |
|---|---|---|
| Build indicator rules | Edit the Pine inputs, plots and conditions directly. | Configure supported indicators and conditions in the Visual Editor. |
| Change custom logic | Write and review the change in Pine Editor. | Ask the AI Coding Agent for a change, then inspect and validate its output. |
| Compare strategy inputs | Record results for each input combination in Strategy Tester. | Use Strategy Optimizer with a strategy and a defined search range. |
Use the Visual Editor to configure supported Supertrend inputs and conditions.
Use the AI Coding Agent when a rule requires custom Pine Script logic.
Keep exported code available for inspection in TradingView Pine Editor.
Step-by-Step Tutorial
Define the event
Specify upward and downward flips, chart timeframe, confirmation timing and optional filters before generating a script.
Configure Supertrend
Open the Visual Editor, add Supertrend, and set ATR length and factor. Use the AI Coding Agent for custom logic beyond the configured rules.
Inspect the generated conditions
Check negative direction for uptrends, previous direction for flips, and a bar-close gate for both markers and alerts.
Validate in TradingView
Add the exported script to Pine Editor, resolve diagnostics, compare closed-bar values, and create the required alerts.
Test a strategy separately
Define order rules and trading costs before comparing input combinations. Keep an evaluation period outside the parameter search.
Trading Strategies & Pro Tips
Unfiltered flip baseline
Leave EMA and ADX off to study the underlying direction changes. For a backtest, specify whether an opposite flip closes a position, reverses it, or is ignored.
EMA-filtered flips
Enable the EMA filter and compare accepted flips with the baseline. A later move across the EMA does not trigger a marker unless another Supertrend flip occurs.
ADX-filtered flips
Enable the ADX threshold and compare the affected bars. This rejects flips under the selected threshold; it cannot certify that the remaining moves will continue.
Common Mistakes to Avoid
- Treating an indicator marker as a filled order or a measured trading result.
- Assuming factor 3 or ATR length 10 is best for every symbol and timeframe.
- Calling the live line fixed because the alert condition waits for a close.
- Expecting EMA or ADX to remove every whipsaw in a range.
- Comparing parameter sets on different sessions, chart types or date ranges.
Frequently Asked Questions
Build and inspect your Supertrend rules
- Configure ATR inputs and explicit direction-change conditions.
- Review generated Pine code and validate chart behavior.
- Compare strategy inputs with costs and a separate evaluation period.
Disclaimer: Trading involves significant risk. The indicators, code, and strategies provided are for educational purposes only and do not constitute financial advice. Past performance is not indicative of future results.