Appearance
MA Cross
Short and long SMA with a mark where they cross.
Kind indicator · Drawn on the price pane
Try it
On the chart, press / and choose MA Cross under Moving averages. To change it, copy the source below into the AlphaScript editor.
Inputs
| Input | Type | Default |
|---|---|---|
| Short MA length | int | 9 |
| Long MA length | int | 21 |
| Source | source | "close" |
| Short color | color | "#FF6D00" |
| Long color | color | "#2962FF" |
| Cross color | color | "#43A047" |
Source
From packages/alphascript/indicators/macross.as.js.
js
indicator({ name: "MA Cross", shortTitle: "MA Cross", overlay: true });
const shortLength = input.int("Short MA length", 9, { min: 1 }), longLength = input.int("Long MA length", 21, { min: 1 });
const src = input.source("Source", "close");
const fast = ta.sma(src, shortLength), slow = ta.sma(src, longLength);
const crossed = ta.cross(fast, slow);
plot(fast, { title: "Short", color: input.color("Short color", "#FF6D00", { group: "Style" }) });
plot(slow, { title: "Long", color: input.color("Long color", "#2962FF", { group: "Style" }) });
plot(ta.calc([crossed, fast], (x, f) => (x ? f : NaN)), { title: "Cross", style: "cross", width: 4, color: input.color("Cross color", "#43A047", { group: "Style" }) });