Appearance
Envelope
SMA with fixed percentage bands.
Kind indicator · Drawn on the price pane
Try it
On the chart, press / and choose Envelope under Bands & channels. To change it, copy the source below into the AlphaScript editor.
Inputs
| Input | Type | Default |
|---|---|---|
| Length | int | 20 |
| Percent | float | 10 |
| Source | source | "close" |
| Basis color | color | "#FF6D00" |
| Upper color | color | "#2962FF" |
| Lower color | color | "#2962FF" |
| Background | color | "rgba(33,150,243,0.05)" |
Source
From packages/alphascript/indicators/envelope.as.js.
js
indicator({ name: "Envelope", shortTitle: "Env", overlay: true });
const length = input.int("Length", 20, { min: 1 });
const percent = input.float("Percent", 10, { step: 0.5 });
const src = input.source("Source", "close");
const basis = ta.sma(src, length);
const upper = ta.calc([basis], (b) => b * (1 + percent / 100)), lower = ta.calc([basis], (b) => b * (1 - percent / 100));
plot(basis, { title: "Basis", color: input.color("Basis color", "#FF6D00", { group: "Style" }) });
plot(upper, { title: "Upper", color: input.color("Upper color", "#2962FF", { group: "Style" }) });
plot(lower, { title: "Lower", color: input.color("Lower color", "#2962FF", { group: "Style" }) });
fill(upper, lower, { title: "Background", color: input.color("Background", "rgba(33,150,243,0.05)", { group: "Style" }) });