Adaptive Supertrend — Trend Drop
# Adaptive Supertrend — Trend Drop
The classic Supertrend is brilliant in trending tape and brutal in chop because the multiplier never changes. This adaptive build flexes the ATR multiplier in real time based on the current volatility regime, so the stop tightens in quiet conditions and widens before the noise can shake you out.
## What it does
- Computes Wilder ATR and compares it to a longer-period ATR average to read the current volatility regime
- Scales the Supertrend multiplier dynamically — tighter stops in low-vol, wider stops in high-vol — clamped between user-defined min/max
- Plots a single supertrend line that flips color green ↔ red as price closes through the trailing stop
- Drops green/red arrows on every flip and paints the candles (optional) so the regime is impossible to miss
- Built-in alerts fire on each long/short flip — wire them straight into thinkorswim notifications
## Recommended settings
- ATR length: **10**
- ATR average length: **50**
- Base multiplier: **2.0**
- Min multiplier: **1.0**
- Max multiplier: **4.0**
- Show flip arrows: **on**
- Color bars: **off** (turn on if you want the candles tinted too)
## Ideal timeframe
Built for 15m–4h swing and 1h–Daily position work where the volatility regime actually shifts enough to matter. On 1m/5m it'll still flip cleanly but the adaptive scaling is most useful on higher timeframes where ATR regime changes are meaningful and slower. Pair with a higher-timeframe trend filter for best results.
## How to use
Treat the colored line as a dynamic trailing stop: long while green, short while red, flat or reverse on a confirmed flip. The arrow is your trigger — fire on the close that confirms it, not intrabar. Because the multiplier widens when volatility expands, you get fewer false flips during news spikes and earnings; in slow grinding tape it tightens and gives you earlier exits. Keep min ≥ 1.0 so the stop never collapses to the bar, and max ≤ 4.0 so it never drifts so wide it becomes useless. If you're seeing too many flips, raise the base multiplier; if you're getting whipsawed, increase ATR length to smooth.
## thinkScript code
```
# ─────────────────────────────────────────────
# │ MarketFragments.com | DNA & Market │
# │ info@marketfragments.com │
# │ www.marketfragments.com │
# ─────────────────────────────────────────────
# Time →
# │
# █ █ █│ █
# █ █ █ │ █ █
# █ █ █ │ █ █ █ ╭─╮
# █ █ █ │ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ ╰─────╯
# ──────┴──────────────────────────────────────────────────────────────
# T1 T2 T3 T4 T5 T6
#
# Adaptive Supertrend — MarketFragments free drop
# Volatility-adaptive Supertrend that scales its ATR multiplier based on
# the ratio of current ATR to a longer-term ATR average. Quiet tape →
# tighter stop. Loud tape → wider stop. Clamped between min/max.
# Free for non-commercial use. Attribution appreciated.
declare upper;
input atrLength = 10;
input atrAvgLength = 50;
input baseMultiplier = 2.0;
input minMultiplier = 1.0;
input maxMultiplier = 4.0;
input showFlipArrows = yes;
input colorBars = no;
# --- ATR + volatility-adaptive multiplier ---
def atr = WildersAverage(TrueRange(high, close, low), atrLength);
def atrAvg = Average(atr, atrAvgLength);
def volRatio = if atrAvg <= 0 then 1 else atr / atrAvg;
def adaptiveMult = Max(minMultiplier, Min(maxMultiplier, baseMultiplier * volRatio));
# --- Basic bands ---
def src = (high + low) / 2;
def upBasic = src + adaptiveMult * atr;
def dnBasic = src - adaptiveMult * atr;
# --- Ratcheting final bands ---
def upperBand = CompoundValue(1,
if upBasic < upperBand[1] or close[1] > upperBand[1] then upBasic else upperBand[1],
upBasic);
def lowerBand = CompoundValue(1,
if dnBasic > lowerBand[1] or close[1] < lowerBand[1] then dnBasic else lowerBand[1],
dnBasic);
# --- Direction: 1 = up (use lower band), -1 = down (use upper band) ---
def dir = CompoundValue(1,
if dir[1] == -1 then (if close > upperBand then 1 else -1)
else (if close < lowerBand then -1 else 1),
1);
# --- Supertrend line (plotted as two colored half-lines) ---
def supertrend = if dir == 1 then lowerBand else upperBand;
plot ST_Up = if dir == 1 then supertrend else Double.NaN;
plot ST_Dn = if dir == -1 then supertrend else Double.NaN;
ST_Up.SetDefaultColor(Color.GREEN);
ST_Dn.SetDefaultColor(Color.RED);
ST_Up.SetLineWeight(2);
ST_Dn.SetLineWeight(2);
ST_Up.HideTitle();
ST_Dn.HideTitle();
# --- Flip arrows ---
plot LongFlip = if showFlipArrows and dir == 1 and dir[1] == -1 then low else Double.NaN;
LongFlip.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LongFlip.SetDefaultColor(Color.GREEN);
LongFlip.SetLineWeight(3);
LongFlip.HideTitle();
plot ShortFlip = if showFlipArrows and dir == -1 and dir[1] == 1 then high else Double.NaN;
ShortFlip.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ShortFlip.SetDefaultColor(Color.RED);
ShortFlip.SetLineWeight(3);
ShortFlip.HideTitle();
# --- Optional candle tint ---
AssignPriceColor(if !colorBars then Color.CURRENT
else if dir == 1 then Color.GREEN
else Color.RED);
# --- Alerts ---
Alert(dir == 1 and dir[1] == -1, "MF Adaptive Supertrend: LONG flip", Alert.BAR, Sound.Ring);
Alert(dir == -1 and dir[1] == 1, "MF Adaptive Supertrend: SHORT flip", Alert.BAR, Sound.Ring);
```
Drop your tweaks, screenshots, and questions below — that's how the library gets better.

