← Script Marketplace
Open-source scriptindicator/v1

Moving Average Cross

by Kodexius·@kodexius·

Plot fast and slow simple moving averages with clear bullish and bearish crossover signals.

#crossover#moving-average#signals#sma
Moving Average Cross chart preview
Open-source script. Everyone can inspect the source code, use the script on a chart, and save an editable copy.

About this script

A straightforward moving-average crossover overlay. Configure the fast and slow lengths, follow both averages on price, and use the included markers and alerts when their order changes.

Source code
mpl-2.0
// Fast and slow simple moving-average crossover
indicator("Moving Average Cross", { overlay: true });

const fastLen = input.number("Fast length", 9, { min: 1, max: 200 });
const slowLen = input.number("Slow length", 21, { min: 2, max: 400 });
const fast = sma(close, fastLen);
const slow = sma(close, slowLen);
const bullish = crossover(fast, slow);
const bearish = crossunder(fast, slow);

plot(fast, { title: "Fast SMA", color: "#22d3ee" });
plot(slow, { title: "Slow SMA", color: "#f59e0b" });
signal(bullish, { position: "belowBar", shape: "arrowUp", color: "#34d399", text: "BUY" });
signal(bearish, { position: "aboveBar", shape: "arrowDown", color: "#f87171", text: "SELL" });

alertcondition(bullish, "Fast SMA crossed above slow SMA");
alertcondition(bearish, "Fast SMA crossed below slow SMA");

Release notes

Initial official release.