Appearance
Volatility Stop
ATR trailing stop that flips with the close.
Kind indicator · Drawn on the price pane
Try it
On the chart, press / and choose Volatility Stop under Trend. To change it, copy the source below into the AlphaScript editor.
Inputs
| Input | Type | Default |
|---|---|---|
| Length | int | 20 |
| Multiplier | float | 2 |
| Source | source | "close" |
| Up color | color | "#089981" |
| Down color | color | "#F23645" |
Source
From packages/alphascript/indicators/volstop.as.js.
js
indicator({ name: "Volatility Stop", shortTitle: "VStop", overlay: true });
const length = input.int("Length", 20, { min: 2 }), factor = input.float("Multiplier", 2, { min: 0.25, step: 0.25 });
const src = input.source("Source", "close");
const atrM = ta.calc([ta.atr(length), ta.tr()], (a, t) => (a === a ? a * factor : t));
const stop = ta.recur([src, atrM], { max: NaN, min: NaN, up: 1, stop: 0 }, (s, x, m) => {
if (s.max !== s.max) { s.max = x; s.min = x; }
s.max = math.max(s.max, x); s.min = math.min(s.min, x);
let st = s.up ? math.max(s.stop, s.max - m) : math.min(s.stop, s.min + m);
if (st !== st) st = x;
const up = x - st >= 0 ? 1 : 0;
if (up !== s.up) { s.max = x; s.min = x; st = up ? x - m : x + m; }
s.up = up; s.stop = st;
return st;
});
plot(stop, { title: "VStop", style: "cross", palette: [input.color("Up color", "#089981", { group: "Style" }), input.color("Down color", "#F23645", { group: "Style" })],
colorIndex: ta.calc([src, stop], (x, s) => (x - s >= 0 ? 0 : 1)) });