OPEN-SOURCE SCRIPT

One-Time 50 SMA Trend Start

34
//version=5
indicator("One-Time 50 SMA Trend Start", overlay=true)

// ─── Inputs ──────────────────────────────────────────────
smaLength = input.int(50, "SMA Length")

// ─── Calculations ────────────────────────────────────────
sma50 = ta.sma(close, smaLength)
crossUp = ta.crossover(close, sma50)

// Track whether we've already fired today
var bool alerted = false

// Reset alert for new session
if ta.change(time("D"))
alerted := false

// Trigger one signal only
signal = crossUp and not alerted
if signal
alerted := true

// ─── Plots ───────────────────────────────────────────────
plot(sma50, color=color.orange, linewidth=2, title="50 SMA")

plotshape(
signal,
title="First Cross Above",
style=shape.triangleup,
color=color.new(color.green, 0),
size=size.large,
location=location.belowbar,
text="Trend"
)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.