Appearance
Moving Average Ribbon
Four moving averages of one type, 20 to 200 bars.
Kind indicator · Drawn on the price pane
Try it
On the chart, press / and choose Moving Average Ribbon under Moving averages. To change it, copy the source below into the AlphaScript editor.
Inputs
| Input | Type | Default |
|---|---|---|
| MA type | select | "SMA" |
| Source | source | "close" |
| MA #1 length | int | 20 |
| MA #2 length | int | 50 |
| MA #3 length | int | 100 |
| MA #4 length | int | 200 |
| MA #1 color | color | "#F6C309" |
| MA #2 color | color | "#FB9800" |
| MA #3 color | color | "#FB6500" |
| MA #4 color | color | "#F60C0C" |
Source
From packages/alphascript/indicators/maribbon.as.js.
js
indicator({ name: "Moving Average Ribbon", shortTitle: "MA Ribbon", overlay: true });
const maType = input.select("MA type", "SMA", ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]);
const src = input.source("Source", "close");
const l1 = input.int("MA #1 length", 20, { min: 1 }), l2 = input.int("MA #2 length", 50, { min: 1 });
const l3 = input.int("MA #3 length", 100, { min: 1 }), l4 = input.int("MA #4 length", 200, { min: 1 });
/** @param {Series} s @param {number} n */
const ma = (s, n) => maType === "EMA" ? ta.ema(s, n) : maType === "SMMA (RMA)" ? ta.rma(s, n) : maType === "WMA" ? ta.wma(s, n) : maType === "VWMA" ? ta.vwma(s, n) : ta.sma(s, n);
plot(ma(src, l1), { title: "MA #1", color: input.color("MA #1 color", "#F6C309", { group: "Style" }) });
plot(ma(src, l2), { title: "MA #2", color: input.color("MA #2 color", "#FB9800", { group: "Style" }) });
plot(ma(src, l3), { title: "MA #3", color: input.color("MA #3 color", "#FB6500", { group: "Style" }) });
plot(ma(src, l4), { title: "MA #4", color: input.color("MA #4 color", "#F60C0C", { group: "Style" }) });