Indicators · condition block
Supertrend
Supertrend is an ATR-based trailing line that sits below price in an uptrend and above it in a downtrend. The block fires when the trend flips, or while it is bullish or bearish.
How the engine evaluates it
Each candle gets a basic upper band hl2 + m × ATR and lower band hl2 − m × ATR, where hl2 is the candle's mid-point and ATR uses Wilder's smoothing.
The final bands only ratchet toward price: the upper band can only move down and the lower band only up, unless the previous close broke through them, in which case they reset to the basic value.
The trend starts bullish at the first candle with a valid ATR. It flips bearish when a close falls below the lower band and bullish when a close rises above the upper band. That first starting direction is not counted as a flip.
flips forms are events on the flip candle; is forms are states. Before your start date the engine loads extra history (at least 50 candles, up to 5,000, scaled to the longest indicator in the bot) so the indicator has settled by the first candle of the run.
upper = hl2 + m × ATR(N), lower = hl2 − m × ATR(N)
bullish → bearish when close < lower band
bearish → bullish when close > upper band
Botscript syntax
In the Lab you pick this block from the Indicators group and fill in its fields. In the code view the same condition is written like this:
supertrend(10,3) flips bullish
supertrend(10,3) flips bearish
supertrend(10,3) is bullish
supertrend(10,3) is bearish
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Condition | flips bullish, flips bearish, is bullish, is bearish | flips bullish | — |
| ATR length | 1 – 5,000 | 10 | — |
| Multiplier | 0.1 – 100 | 3 | Larger values flip less often. |
| Timeframe | the run's candles, or 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w | the run's candles | Optional. At least the run's candle size and a whole multiple of it. |
On a higher timeframe
Add a timeframe at the end to read Supertrend from bigger candles than the run uses, for example supertrend(10,3) is bullish on 1d. The engine builds those candles from the run's own candles (UTC, weeks start on Monday) and evaluates the block only on candles that have closed, so there is no look-ahead. Lengths and lookbacks count the bigger candles.
On a higher timeframe flips bullish and flips bearish are events: they fire once, on the run candle that closes the bigger candle where they happened. is bullish and is bearish are states that hold until the next bigger candle closes.
The timeframe must be at least the run's candle size and a whole multiple of it; otherwise the run stops with an error and is not charged. Multi-timeframe conditions covers the details, including warm-up.
How traders use it
- Always-in-trend systems: buy on
flips bullish, sell onflips bearish. - Trend filter:
supertrend(10,3) is bullishin front of an oscillator entry. - Add
adx(14) > 25to ignore flips in flat markets.
Example bot
bot "Supertrend Rider"
when supertrend(10,3) flips bullish and adx(14) > 20
then buy 100%
when supertrend(10,3) flips bearish
then sell 100%
- Buys when Supertrend turns bullish while ADX shows some trend strength.
- Sells when it turns bearish.
Pitfalls
- In sideways markets Supertrend flips back and forth.
- A larger multiplier holds trends longer but gives back more before exiting.
Supertrend: frequently asked questions
Is this the same Supertrend as TradingView?
It follows the standard definition: hl2 ± multiplier × ATR with ratcheting bands and close-based flips. ATR is Wilder's.
Does the first candle count as a flip?
No. The trend is seeded bullish when ATR first exists and only later changes count as flips.
What do 10 and 3 mean?
ATR length 10 and band width 3 × ATR, the most common settings.
Can I use it as a stop?
Yes: supertrend(10,3) flips bearish with sell 100% acts as a trailing stop.
Related blocks
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.