This complete v6 indicator plots a simple moving average and marks a close crossing above it. It has no orders, stop, or profit target. The crossover is calculated on every execution, then the marker waits for the chart bar to close. The example teaches inputs, series calculations, a plot, and an alert condition.
Complete indicator: SMA and a confirmed close crossoverpinescript
//@version=6
indicator("First Pine Script: SMA Cross", overlay=true)
length = input.int(20, "SMA length", minval=1)
average = ta.sma(close, length)
crossedAbove = ta.crossover(close, average)
confirmedCross = crossedAbove and barstate.isconfirmed
plot(average, "SMA", color=color.blue, linewidth=2)
plotshape(confirmedCross, title="Confirmed cross", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)
alertcondition(confirmedCross, "Close crossed above SMA", "The bar closed across its SMA.")