ATR Volatility Stop — Volatility Drop
A Wilder-smoothed ATR trailing stop that ratchets with the trend and flips when price closes through it. One number, one line — but it handles your stop, your trend bias, and your flip alerts in a single study.
## What it does
- Computes Wilder's ATR and projects a trailing stop at `Source − Mult × ATR` (long) or `Source + Mult × ATR` (short).
- Ratchets the long stop up and the short stop down as the trend extends — never loosens.
- Flips trend when the source closes through the active stop, then re-seeds the new-direction stop on the flip bar.
- Colors the stop green/red by trend, prints up/down arrows on each flip, and tints the chart background by regime.
- Fires two alerts: one on each LONG flip, one on each SHORT flip.
## Recommended settings
- ATR Length: **14** (Wilder's smoothing)
- ATR Multiplier: **3.0** (tighter = more flips; wider = fewer, slower flips)
- Source: **close**
## Ideal timeframe
Works on any chart; sweet spots are the daily for swing position management and the 15m / 1H for intraday trailing stops.
## How to use
Use it as a regime filter *and* a stop. Only take longs while the line is green and below price; only take shorts while it's red and above price. The flip arrow is the signal to flatten, reverse, or stand down — pair it with a structure level (prior swing, VWAP, daily pivot) for the highest-quality entries. On choppy days the multiplier earns its keep: bump it to 4.0–5.0 to ride through noise; drop it to 2.0 for fast scalps.
## thinkScript code
```
# ─────────────────────────────────────────────
# │ MarketFragments.com | DNA & Market │
# │ info@marketfragments.com │
# │ www.marketfragments.com │
# ─────────────────────────────────────────────
# Time →
# │
# █ █ █│ █
# █ █ █ │ █ █
# █ █ █ │ █ █ █ ╭─╮
# █ █ █ │ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ ╰─────╯
# ──────┴──────────────────────────────────────────────────────────────
# T1 T2 T3 T4 T5 T6
#
# ATR Volatility Stop
# Wilder's ATR trailing stop with auto trend-flip and arrows + alerts.
# Free for non-commercial use. Tweaks and forks welcome.
input atrLength = 14;
input atrMult = 3.0;
input source = close;
# Wilder's ATR
def TR = TrueRange(high, close, low);
def ATR = MovingAverage(AverageType.WILDERS, TR, atrLength);
def longStopRaw = source - atrMult * ATR;
def shortStopRaw = source + atrMult * ATR;
# Trend state: 1 = long regime, -1 = short regime
def trend = CompoundValue(1,
if source > stop[1] and trend[1] == -1 then 1
else if source < stop[1] and trend[1] == 1 then -1
else trend[1],
1);
# Stop line: ratchets in the current trend, re-seeds on flip
def stop = CompoundValue(1,
if trend == 1 and trend[1] == 1 then Max(longStopRaw, stop[1])
else if trend == -1 and trend[1] == -1 then Min(shortStopRaw, stop[1])
else if trend == 1 then longStopRaw
else shortStopRaw,
longStopRaw);
plot Stop = stop;
Stop.AssignValueColor(if trend == 1 then Color.GREEN else Color.RED);
Stop.SetLineWeight(2);
def flipUp = trend == 1 and trend[1] == -1;
def flipDown = trend == -1 and trend[1] == 1;
plot FlipUpArrow = if flipUp then low - 0.5 * ATR else Double.NaN;
FlipUpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
FlipUpArrow.SetDefaultColor(Color.GREEN);
FlipUpArrow.SetLineWeight(3);
plot FlipDownArrow = if flipDown then high + 0.5 * ATR else Double.NaN;
FlipDownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
FlipDownArrow.SetDefaultColor(Color.RED);
FlipDownArrow.SetLineWeight(3);
AssignBackgroundColor(if trend == 1 then CreateColor(0, 30, 0) else CreateColor(30, 0, 0));
Alert(flipUp, "ATR Volatility Stop flipped LONG", Alert.BAR, Sound.Chimes);
Alert(flipDown, "ATR Volatility Stop flipped SHORT", Alert.BAR, Sound.Bell);
```
Drop your tweaks, screenshots, and questions below — that's how the library gets better.

