Skip to content

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 ​

InputTypeDefault
Short MA lengthint9
Long MA lengthint21
Sourcesource"close"
Short colorcolor"#FF6D00"
Long colorcolor"#2962FF"
Cross colorcolor"#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" }) });

AlphaScript language v0.1 · runtime 0.2.0